[json-glib] core: Add json_parser_steal_root()
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [json-glib] core: Add json_parser_steal_root()
- Date: Sat, 18 Mar 2017 18:24:14 +0000 (UTC)
commit 0f6e3d3eddc3bdb321283998924506d9184a0a2a
Author: Ole André Vadla Ravnås <oleavr gmail com>
Date: Tue Mar 14 18:27:13 2017 +0100
core: Add json_parser_steal_root()
This avoids copying the root node for the parse-to-node use-case.
https://bugzilla.gnome.org/show_bug.cgi?id=774688
doc/json-glib-sections.txt | 1 +
json-glib/json-parser.c | 26 ++++++++++++++++++++++++++
json-glib/json-parser.h | 2 ++
3 files changed, 29 insertions(+), 0 deletions(-)
---
diff --git a/doc/json-glib-sections.txt b/doc/json-glib-sections.txt
index c3152ab..047f03e 100644
--- a/doc/json-glib-sections.txt
+++ b/doc/json-glib-sections.txt
@@ -186,6 +186,7 @@ json_parser_load_from_stream_finish
<SUBSECTION>
json_parser_get_root
+json_parser_steal_root
<SUBSECTION>
json_parser_get_current_line
diff --git a/json-glib/json-parser.c b/json-glib/json-parser.c
index dda3eeb..f2a99d9 100644
--- a/json-glib/json-parser.c
+++ b/json-glib/json-parser.c
@@ -1198,6 +1198,32 @@ json_parser_get_root (JsonParser *parser)
}
/**
+ * json_parser_steal_root:
+ * @parser: a #JsonParser
+ *
+ * Steals the top level node from the parsed JSON stream.
+ *
+ * Returns: (transfer full): the top level #JsonNode
+ *
+ * Since: 1.4
+ */
+JsonNode *
+json_parser_steal_root (JsonParser *parser)
+{
+ JsonParserPrivate *priv;
+ JsonNode *root;
+
+ g_return_val_if_fail (JSON_IS_PARSER (parser), NULL);
+
+ priv = parser->priv;
+
+ root = priv->root;
+ priv->root = NULL;
+
+ return root;
+}
+
+/**
* json_parser_get_current_line:
* @parser: a #JsonParser
*
diff --git a/json-glib/json-parser.h b/json-glib/json-parser.h
index c7223d2..1470fbf 100644
--- a/json-glib/json-parser.h
+++ b/json-glib/json-parser.h
@@ -176,6 +176,8 @@ gboolean json_parser_load_from_stream_finish (JsonParser *parser,
JSON_AVAILABLE_IN_1_0
JsonNode * json_parser_get_root (JsonParser *parser);
+JSON_AVAILABLE_IN_1_4
+JsonNode * json_parser_steal_root (JsonParser *parser);
JSON_AVAILABLE_IN_1_0
guint json_parser_get_current_line (JsonParser *parser);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]