Chlumsky/json-cpp-gen

Provide string length to serializer write function

Chlumsky opened this issue · 2 comments

The serializer function void write(const char *str); could have the length of str passed as a second argument, since it is a literal in the majority of the cases. This could very slightly improve performance since string length is almost surely computed when appending to the output JSON string. String API would have to be updated to allow appending a string with known length.

Implement this by adding

"appendStringLiteral": "$S += $X"

to the string API (can be replaced by e.g. $S += StringRef($X, sizeof($X)-1)) and try to eliminate the write function from the serializer completely. Make sure that the string API is not called with expressions with side effects.

Implemented in 9c4f518