aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPetri Lehtinen <petri@digip.org>2009-09-03 21:30:36 +0300
committerPetri Lehtinen <petri@digip.org>2009-09-04 09:52:40 +0300
commit93c5892bc3a8138ba44a626d0172563a714e5b64 (patch)
treeb53d0baae082b75f8402d5354f9218ec96ae6ccd /src
parent1095ca956b360a3614392f88b2dc132d89ef00a1 (diff)
downloadjansson-93c5892bc3a8138ba44a626d0172563a714e5b64.zip
jansson-93c5892bc3a8138ba44a626d0172563a714e5b64.tar.gz
jansson-93c5892bc3a8138ba44a626d0172563a714e5b64.tar.bz2
load: Factor out an unneeded strdup
By "stealing" the string parsed out in lexer, one strdup can be saved.
Diffstat (limited to 'src')
-rw-r--r--src/load.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/load.c b/src/load.c
index 25df182..1e2ad2a 100644
--- a/src/load.c
+++ b/src/load.c
@@ -544,6 +544,17 @@ out:
return lex->token;
}
+static char *lex_steal_string(lex_t *lex)
+{
+ char *result = NULL;
+ if(lex->token == TOKEN_STRING)
+ {
+ result = lex->value.string;
+ lex->value.string = NULL;
+ }
+ return result;
+}
+
static int lex_init(lex_t *lex, get_func get, eof_func eof, void *data)
{
stream_init(&lex->stream, get, eof, data);
@@ -587,7 +598,7 @@ static json_t *parse_object(lex_t *lex, json_error_t *error)
goto error;
}
- key = strdup(lex->value.string);
+ key = lex_steal_string(lex);
if(!key)
return NULL;