Skip to content

Commit b7522ac

Browse files
committed
encoder: Optimise encoding simple values
1 parent 7f5e98f commit b7522ac

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

php_simdjson.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -465,30 +465,30 @@ static zend_always_inline bool simdjson_validate_encode_depth(const zend_long de
465465

466466
#if PHP_VERSION_ID >= 80200
467467
/** For simple types we can just return direct interned string without allocating new strings */
468-
static zend_always_inline bool simdjson_encode_simple(const zval *parameter, zval *return_value, zend_long options) {
468+
static zend_always_inline bool simdjson_encode_simple(const zval *parameter, zval *return_value) {
469469
switch (Z_TYPE_P(parameter)) {
470470
case IS_NULL:
471-
RETVAL_STR(ZSTR_KNOWN(ZEND_STR_NULL_LOWERCASE));
471+
RETVAL_INTERNED_STR(ZSTR_KNOWN(ZEND_STR_NULL_LOWERCASE));
472472
return true;
473473

474474
case IS_TRUE:
475-
RETVAL_STR(ZSTR_KNOWN(ZEND_STR_TRUE));
475+
RETVAL_INTERNED_STR(ZSTR_KNOWN(ZEND_STR_TRUE));
476476
return true;
477477

478478
case IS_FALSE:
479-
RETVAL_STR(ZSTR_KNOWN(ZEND_STR_FALSE));
479+
RETVAL_INTERNED_STR(ZSTR_KNOWN(ZEND_STR_FALSE));
480480
return true;
481481

482482
case IS_LONG:
483483
if (Z_LVAL_P(parameter) >= 0 && Z_LVAL_P(parameter) < 10) {
484-
RETVAL_STR(ZSTR_CHAR((unsigned char) '0' + Z_LVAL_P(parameter)));
484+
RETVAL_INTERNED_STR(ZSTR_CHAR((unsigned char) '0' + Z_LVAL_P(parameter)));
485485
return true;
486486
}
487487
break;
488488

489489
case IS_ARRAY:
490490
if (zend_hash_num_elements(Z_ARRVAL_P(parameter)) == 0) {
491-
RETVAL_STR(simdjson_json_empty_array);
491+
RETVAL_INTERNED_STR(simdjson_json_empty_array);
492492
return true;
493493
}
494494
break;
@@ -517,7 +517,7 @@ PHP_FUNCTION(simdjson_encode) {
517517
}
518518

519519
#if PHP_VERSION_ID >= 80200
520-
if (!(options & SIMDJSON_APPEND_NEWLINE) && simdjson_encode_simple(parameter, return_value, options)) {
520+
if (!(options & SIMDJSON_APPEND_NEWLINE) && simdjson_encode_simple(parameter, return_value)) {
521521
return;
522522
}
523523
#endif

0 commit comments

Comments
 (0)