aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>2014-05-09 11:32:28 +0300
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>2014-05-09 12:46:21 +0300
commitd3c72e23df6ef1fde8122db589d12d49c8495535 (patch)
tree801f175510fff7f438e5c4abc3bca5c81dba70d1 /src
parent14d309cc55d88b73d4c9d1fa51b535ae491405fd (diff)
downloadpostgresql-d3c72e23df6ef1fde8122db589d12d49c8495535.tar.gz
postgresql-d3c72e23df6ef1fde8122db589d12d49c8495535.zip
Avoid some pnstrdup()s when constructing jsonb
This speeds up text to jsonb parsing and hstore to jsonb conversions somewhat.
Diffstat (limited to 'src')
-rw-r--r--src/backend/utils/adt/json.c3
-rw-r--r--src/backend/utils/adt/jsonb.c4
-rw-r--r--src/include/utils/jsonapi.h4
3 files changed, 6 insertions, 5 deletions
diff --git a/src/backend/utils/adt/json.c b/src/backend/utils/adt/json.c
index 16f4eccc06e..e2db24520eb 100644
--- a/src/backend/utils/adt/json.c
+++ b/src/backend/utils/adt/json.c
@@ -381,9 +381,6 @@ parse_object_field(JsonLexContext *lex, JsonSemAction *sem)
if (oend != NULL)
(*oend) (sem->semstate, fname, isnull);
-
- if (fname != NULL)
- pfree(fname);
}
static void
diff --git a/src/backend/utils/adt/jsonb.c b/src/backend/utils/adt/jsonb.c
index e1fe45f7128..2fd87fc9e1a 100644
--- a/src/backend/utils/adt/jsonb.c
+++ b/src/backend/utils/adt/jsonb.c
@@ -247,7 +247,7 @@ jsonb_in_object_field_start(void *pstate, char *fname, bool isnull)
Assert(fname != NULL);
v.type = jbvString;
v.val.string.len = checkStringLen(strlen(fname));
- v.val.string.val = pnstrdup(fname, v.val.string.len);
+ v.val.string.val = fname;
_state->res = pushJsonbValue(&_state->parseState, WJB_KEY, &v);
}
@@ -295,7 +295,7 @@ jsonb_in_scalar(void *pstate, char *token, JsonTokenType tokentype)
Assert(token != NULL);
v.type = jbvString;
v.val.string.len = checkStringLen(strlen(token));
- v.val.string.val = pnstrdup(token, v.val.string.len);
+ v.val.string.val = token;
break;
case JSON_TOKEN_NUMBER:
diff --git a/src/include/utils/jsonapi.h b/src/include/utils/jsonapi.h
index 889364fb30e..df057121a11 100644
--- a/src/include/utils/jsonapi.h
+++ b/src/include/utils/jsonapi.h
@@ -73,6 +73,10 @@ typedef void (*json_scalar_action) (void *state, char *token, JsonTokenType toke
* point, Likewise, semstate can be NULL. Using an all-NULL structure amounts
* to doing a pure parse with no side-effects, and is therefore exactly
* what the json input routines do.
+ *
+ * The 'fname' and 'token' strings passed to these actions are palloc'd.
+ * They are not free'd or used further by the parser, so the action function
+ * is free to do what it wishes with them.
*/
typedef struct JsonSemAction
{