Skip to content

Commit f26aae1

Browse files
committed
Microoptimize zval_long_or_null_to_lexbor_str
Based on Nora's suggestion of not using an unnecesary allocation.
1 parent 8f44bd9 commit f26aae1

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

ext/uri/uri_parser_whatwg.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ static zend_always_inline void zval_string_or_null_to_lexbor_str(const zval *val
4343
static zend_always_inline void zval_long_or_null_to_lexbor_str(const zval *value, lexbor_str_t *lexbor_str)
4444
{
4545
if (Z_TYPE_P(value) == IS_LONG) {
46-
zend_string *tmp = zend_long_to_str(Z_LVAL_P(value));
47-
lexbor_str_init_append(lexbor_str, lexbor_parser.mraw, (const lxb_char_t *) ZSTR_VAL(tmp), ZSTR_LEN(tmp));
48-
zend_string_release(tmp);
46+
char buf[MAX_LENGTH_OF_LONG + 1];
47+
const char *res = zend_print_long_to_buf(buf + sizeof(buf) - 1, Z_LVAL_P(value));
48+
lexbor_str_init_append(lexbor_str, lexbor_parser.mraw, (const lxb_char_t *) res, strlen(res));
4949
} else {
5050
ZEND_ASSERT(Z_ISNULL_P(value));
5151
lexbor_str->data = (lxb_char_t *) "";

0 commit comments

Comments
 (0)