After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 774688 - json_from_string() could be optimized to avoid copying the root node
json_from_string() could be optimized to avoid copying the root node
Status: RESOLVED FIXED
Product: json-glib
Classification: Core
Component: Core
git master
Other Mac OS
: Normal enhancement
: ---
Assigned To: json-glib-maint
json-glib-maint
Depends on:
Blocks:
 
 
Reported: 2016-11-18 18:41 UTC by Ole André Vadla Ravnås
Modified: 2017-03-18 18:24 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
core: Add json_parser_unref_to_node() (2.51 KB, patch)
2016-11-18 18:48 UTC, Ole André Vadla Ravnås
none Details | Review
core: Optimize json_from_string() to avoid copy (993 bytes, patch)
2016-11-18 18:49 UTC, Ole André Vadla Ravnås
none Details | Review
core: Add json_parser_steal_root() (1.78 KB, patch)
2017-03-14 17:22 UTC, Ole André Vadla Ravnås
none Details | Review
core: Optimize json_from_string() to avoid copy (768 bytes, patch)
2017-03-14 17:23 UTC, Ole André Vadla Ravnås
committed Details | Review
core: Add json_parser_steal_root() (2.20 KB, patch)
2017-03-14 17:29 UTC, Ole André Vadla Ravnås
committed Details | Review

Description Ole André Vadla Ravnås 2016-11-18 18:41:01 UTC
Please see the enclosed patch.
Comment 1 Ole André Vadla Ravnås 2016-11-18 18:48:39 UTC
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.
Comment 2 Ole André Vadla Ravnås 2016-11-18 18:49:12 UTC
Created attachment 340264 [details] [review]
core: Optimize json_from_string() to avoid copy
Comment 3 Emmanuele Bassi (:ebassi) 2017-03-11 16:04:38 UTC
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.
Comment 4 Emmanuele Bassi (:ebassi) 2017-03-11 16:05:30 UTC
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.
Comment 5 Emmanuele Bassi (:ebassi) 2017-03-11 16:06:53 UTC
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.
Comment 6 Ole André Vadla Ravnås 2017-03-14 17:22:00 UTC
(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.
Comment 7 Ole André Vadla Ravnås 2017-03-14 17:22:50 UTC
Created attachment 347932 [details] [review]
core: Add json_parser_steal_root()
Comment 8 Ole André Vadla Ravnås 2017-03-14 17:23:30 UTC
Created attachment 347933 [details] [review]
core: Optimize json_from_string() to avoid copy
Comment 9 Ole André Vadla Ravnås 2017-03-14 17:29:15 UTC
Created attachment 347934 [details] [review]
core: Add json_parser_steal_root()

Updated to also add the new symbol to gtk-doc.
Comment 10 Ole André Vadla Ravnås 2017-03-14 17:30:38 UTC
Patches should now be ready for another review. Cheers!
Comment 11 Emmanuele Bassi (:ebassi) 2017-03-18 18:24:44 UTC
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.