GNOME Bugzilla – Bug 774688
json_from_string() could be optimized to avoid copying the root node
Last modified: 2017-03-18 18:24:51 UTC
Please see the enclosed patch.
Created attachment 340263 [details] [review] core: Add json_parser_unref_to_node() This simplifies the parse-to-node use-case and also avoids copying the root node for most cases. This was inspired by the GBytes API. The alternative would be something like json_parser_steal_root() -- let me know if you'd prefer that.
Created attachment 340264 [details] [review] core: Optimize json_from_string() to avoid copy
I'd rather go with the steal_root() variant. Using "unref_to_node()" with a GObject is a bit of a hit and miss, especially when it comes to higher level languages.
Review of attachment 340263 [details] [review]: The patch would also need to add the new symbol to gtk-doc. ::: json-glib/json-parser.h @@ +150,3 @@ JSON_AVAILABLE_IN_1_2 JsonParser *json_parser_new_immutable (void); +JSON_AVAILABLE_IN_1_2 New API should go in 1.4, at this point.
Review of attachment 340264 [details] [review]: ::: json-glib/json-utils.c @@ +63,3 @@ } + return json_parser_unref_to_node (parser); With a change to: retval = json_parser_steal_root (parser); g_object_unref (parser); return retval; looks good to me.
(In reply to Emmanuele Bassi (:ebassi) from comment #3) > I'd rather go with the steal_root() variant. Using "unref_to_node()" with a > GObject is a bit of a hit and miss, especially when it comes to higher level > languages. Good point! Thanks for reviewing – I'll update the patches to use this approach.
Created attachment 347932 [details] [review] core: Add json_parser_steal_root()
Created attachment 347933 [details] [review] core: Optimize json_from_string() to avoid copy
Created attachment 347934 [details] [review] core: Add json_parser_steal_root() Updated to also add the new symbol to gtk-doc.
Patches should now be ready for another review. Cheers!
Attachment 347933 [details] pushed as 7d79960 - core: Optimize json_from_string() to avoid copy Attachment 347934 [details] pushed as 0f6e3d3 - core: Add json_parser_steal_root() I've pushed 347934 with a slight change to fix the introspection annotation.