Skip to content

Commit

Permalink
json2code: optimize string handling using std::string_view
Browse files Browse the repository at this point in the history
Replace seastar::sstring with std::string_view for enum string literals
in generated C++ service code. Since these strings are only used for
comparison with HTTP query parameters and don't require modification,
std::string_view provides a more lightweight alternative without the
overhead of string allocation and copying.

This change improves both runtime performance and memory efficiency
of the generated service code.

Signed-off-by: Kefu Chai <[email protected]>

Closes #2657
  • Loading branch information
tchaikov authored and xemul committed Feb 26, 2025
1 parent c3e444c commit fb4a7b6
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion scripts/seastar-json2code.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def indent_body(s, level):
name_list = ',\n'.join(f'"{enum}"' for enum in enums)
parse_func = Template('''\
$type_name str2$type_name(const sstring& str) {
static const sstring arr[] = {
static const std::string_view arr[] = {
$name_list
};
int i;
Expand Down

0 comments on commit fb4a7b6

Please sign in to comment.