mirror of
https://github.com/postgres/postgres.git
synced 2025-11-21 00:42:43 +03:00
Micro-optimize datum_to_json_internal() some more.
Commit dc3f9bc549 mainly targeted the JSONTYPE_NUMERIC code path.
This commit applies similar optimizations (e.g., removing
unnecessary runtime calls to strlen() and palloc()) to nearby code.
Reviewed-by: Tom Lane
Discussion: https://postgr.es/m/20231208203708.GA4126315%40nathanxps13
This commit is contained in:
@@ -188,7 +188,7 @@ datum_to_json_internal(Datum val, bool is_null, StringInfo result,
|
||||
|
||||
if (is_null)
|
||||
{
|
||||
appendStringInfoString(result, "null");
|
||||
appendBinaryStringInfo(result, "null", strlen("null"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -210,11 +210,14 @@ datum_to_json_internal(Datum val, bool is_null, StringInfo result,
|
||||
composite_to_json(val, result, false);
|
||||
break;
|
||||
case JSONTYPE_BOOL:
|
||||
outputstr = DatumGetBool(val) ? "true" : "false";
|
||||
if (key_scalar)
|
||||
escape_json(result, outputstr);
|
||||
appendStringInfoChar(result, '"');
|
||||
if (DatumGetBool(val))
|
||||
appendBinaryStringInfo(result, "true", strlen("true"));
|
||||
else
|
||||
appendStringInfoString(result, outputstr);
|
||||
appendBinaryStringInfo(result, "false", strlen("false"));
|
||||
if (key_scalar)
|
||||
appendStringInfoChar(result, '"');
|
||||
break;
|
||||
case JSONTYPE_NUMERIC:
|
||||
outputstr = OidOutputFunctionCall(outfuncoid, val);
|
||||
@@ -277,9 +280,8 @@ datum_to_json_internal(Datum val, bool is_null, StringInfo result,
|
||||
case JSONTYPE_CAST:
|
||||
/* outfuncoid refers to a cast function, not an output function */
|
||||
jsontext = DatumGetTextPP(OidFunctionCall1(outfuncoid, val));
|
||||
outputstr = text_to_cstring(jsontext);
|
||||
appendStringInfoString(result, outputstr);
|
||||
pfree(outputstr);
|
||||
appendBinaryStringInfo(result, VARDATA_ANY(jsontext),
|
||||
VARSIZE_ANY_EXHDR(jsontext));
|
||||
pfree(jsontext);
|
||||
break;
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user