Message ID | 20240701110257.1052377-3-whitecrowbar@gmail.com |
---|---|
State | Under Review |
Delegated to: | Ilya Maximets |
Headers | show |
Series | Optimize json serialization 2.3 times | expand |
Context | Check | Description |
---|---|---|
ovsrobot/apply-robot | success | apply and check: success |
ovsrobot/github-robot-_Build_and_Test | success | github build: passed |
ovsrobot/intel-ovs-compilation | success | test: success |
On 1 Jul 2024, at 13:02, Grigorii Nazarov wrote: > Signed-off-by: Grigorii Nazarov <whitecrowbar@gmail.com> > --- > There's an open question on whether this function should exist, or being > placed in header etc. However, no decision was made yet. I looked at the previous discussion, I’m fine with just keeping this API. If we want to inline it, we need to expose json_serialize_string which then it might be better to just use/expose that API instead. Anyway; Acked-by: Eelco Chaudron <echaudro@redhat.com> > v2: fixed title > v4: changed patch number from 3/4 to 2/3 > > lib/json.c | 11 ++++------- > 1 file changed, 4 insertions(+), 7 deletions(-) > > diff --git a/lib/json.c b/lib/json.c > index 001f6e6ab..d40e93857 100644 > --- a/lib/json.c > +++ b/lib/json.c > @@ -127,7 +127,9 @@ static void json_parser_input(struct json_parser *, struct json_token *); > > static void json_error(struct json_parser *p, const char *format, ...) > OVS_PRINTF_FORMAT(2, 3); > - > + > +static void json_serialize_string(const char *, struct ds *); > + > const char * > json_type_to_string(enum json_type type) > { > @@ -987,11 +989,7 @@ exit: > void > json_string_escape(const char *in, struct ds *out) > { > - struct json json = { > - .type = JSON_STRING, > - .string = CONST_CAST(char *, in), > - }; > - json_to_ds(&json, 0, out); > + json_serialize_string(in, out); > } > > static void > @@ -1572,7 +1570,6 @@ static void json_serialize_object(const struct shash *object, > struct json_serializer *); > static void json_serialize_array(const struct json_array *, > struct json_serializer *); > -static void json_serialize_string(const char *, struct ds *); > > /* Converts 'json' to a string in JSON format, encoded in UTF-8, and returns > * that string. The caller is responsible for freeing the returned string, > -- > 2.45.2 > > _______________________________________________ > dev mailing list > dev@openvswitch.org > https://mail.openvswitch.org/mailman/listinfo/ovs-dev
On 6 Sep 2024, at 12:24, Eelco Chaudron wrote: > On 1 Jul 2024, at 13:02, Grigorii Nazarov wrote: > >> Signed-off-by: Grigorii Nazarov <whitecrowbar@gmail.com> >> --- >> There's an open question on whether this function should exist, or being >> placed in header etc. However, no decision was made yet. > > I looked at the previous discussion, I’m fine with just keeping this API. > > If we want to inline it, we need to expose json_serialize_string which then it might be better to just use/expose that API instead. > > Anyway; > > Acked-by: Eelco Chaudron <echaudro@redhat.com> Forgot to add a small nit, see below. >> v2: fixed title >> v4: changed patch number from 3/4 to 2/3 >> >> lib/json.c | 11 ++++------- >> 1 file changed, 4 insertions(+), 7 deletions(-) >> >> diff --git a/lib/json.c b/lib/json.c >> index 001f6e6ab..d40e93857 100644 >> --- a/lib/json.c >> +++ b/lib/json.c >> @@ -127,7 +127,9 @@ static void json_parser_input(struct json_parser *, struct json_token *); >> >> static void json_error(struct json_parser *p, const char *format, ...) >> OVS_PRINTF_FORMAT(2, 3); >> - >> + >> +static void json_serialize_string(const char *, struct ds *); >> + >> const char * >> json_type_to_string(enum json_type type) >> { >> @@ -987,11 +989,7 @@ exit: >> void >> json_string_escape(const char *in, struct ds *out) >> { >> - struct json json = { >> - .type = JSON_STRING, >> - .string = CONST_CAST(char *, in), >> - }; >> - json_to_ds(&json, 0, out); >> + json_serialize_string(in, out); >> } >> >> static void >> @@ -1572,7 +1570,6 @@ static void json_serialize_object(const struct shash *object, >> struct json_serializer *); >> static void json_serialize_array(const struct json_array *, >> struct json_serializer *); >> -static void json_serialize_string(const char *, struct ds *); If we move the static definition, I would move all of them, so they are at one location. >> /* Converts 'json' to a string in JSON format, encoded in UTF-8, and returns >> * that string. The caller is responsible for freeing the returned string, >> -- >> 2.45.2 >> >> _______________________________________________ >> dev mailing list >> dev@openvswitch.org >> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
diff --git a/lib/json.c b/lib/json.c index 001f6e6ab..d40e93857 100644 --- a/lib/json.c +++ b/lib/json.c @@ -127,7 +127,9 @@ static void json_parser_input(struct json_parser *, struct json_token *); static void json_error(struct json_parser *p, const char *format, ...) OVS_PRINTF_FORMAT(2, 3); - + +static void json_serialize_string(const char *, struct ds *); + const char * json_type_to_string(enum json_type type) { @@ -987,11 +989,7 @@ exit: void json_string_escape(const char *in, struct ds *out) { - struct json json = { - .type = JSON_STRING, - .string = CONST_CAST(char *, in), - }; - json_to_ds(&json, 0, out); + json_serialize_string(in, out); } static void @@ -1572,7 +1570,6 @@ static void json_serialize_object(const struct shash *object, struct json_serializer *); static void json_serialize_array(const struct json_array *, struct json_serializer *); -static void json_serialize_string(const char *, struct ds *); /* Converts 'json' to a string in JSON format, encoded in UTF-8, and returns * that string. The caller is responsible for freeing the returned string,
Signed-off-by: Grigorii Nazarov <whitecrowbar@gmail.com> --- There's an open question on whether this function should exist, or being placed in header etc. However, no decision was made yet. v2: fixed title v4: changed patch number from 3/4 to 2/3 lib/json.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)