Skip to content

Commit

Permalink
Eliminate useless string copy
Browse files Browse the repository at this point in the history
  • Loading branch information
Crayon2000 committed Nov 10, 2024
1 parent 5850eb3 commit 29a0c84
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions source/vpad_to_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,15 @@ void pad_to_json(PADData pad_data, char* out, uint32_t out_size)
}

// Convert to string
char* s = json_dumps(root, JSON_COMPACT | JSON_REAL_PRECISION(10));
strncpy(out, s, out_size);
free(s);
const size_t real_size = json_dumpb(root, out, out_size, JSON_COMPACT | JSON_REAL_PRECISION(10));
if(real_size < out_size)
{
out[real_size] = '\0';
}
else
{
out[0] = '\0';
}

json_decref(root);
}

0 comments on commit 29a0c84

Please sign in to comment.