1. Andrew Dunstan
  2. pgdevel

Commits

Andrew Dunstan  committed 139043d

Don't copy tokens unless needed

  • Participants
  • Parent commits b70fab3

Comments (0)

Files changed (1)

File src/backend/utils/adt/json.c

View file
  • Ignore whitespace
 {
 	char	   *val = NULL;
 	json_scalar_action sfunc = sem->scalar;
+	char	   **valaddr;
 	JsonTokenType tok = lex_peek(lex);
 
-	if (lex_accept(lex, JSON_TOKEN_TRUE, &val) ||
-		lex_accept(lex, JSON_TOKEN_FALSE, &val) ||
-		lex_accept(lex, JSON_TOKEN_NULL, &val) ||
-		lex_accept(lex, JSON_TOKEN_NUMBER, &val) ||
-		lex_accept(lex, JSON_TOKEN_STRING, &val))
+	valaddr  = sfunc == NULL ? NULL : &val;
+
+	if (lex_accept(lex, JSON_TOKEN_TRUE, valaddr) ||
+		lex_accept(lex, JSON_TOKEN_FALSE, valaddr) ||
+		lex_accept(lex, JSON_TOKEN_NULL, valaddr) ||
+		lex_accept(lex, JSON_TOKEN_NUMBER, valaddr) ||
+		lex_accept(lex, JSON_TOKEN_STRING, valaddr))
 	{
 		if (sfunc != NULL)
 			(*sfunc) (sem->semstate, val, tok);
 	json_ofield_action ostart = sem->object_field_start;
 	json_ofield_action oend = sem->object_field_end;
 	bool		isnull;
+	char      **fnameaddr = NULL;
+
+	if (ostart != NULL || oend != NULL)
+		fnameaddr = &fname;
 
-	if (!lex_accept(lex, JSON_TOKEN_STRING, &fname))
+	if (!lex_accept(lex, JSON_TOKEN_STRING, fnameaddr))
 		report_parse_error(JSON_PARSE_STRING, lex);
 
 	lex_expect(JSON_PARSE_OBJECT_LABEL, lex, JSON_TOKEN_COLON);