Skip to content

Commit f039bae

Browse files
committed
Optimize serializing class names
Because of the memcpy, compilers can't infer that ZSTR_LEN (i.e. class_name->len) did not change, so they copy it out of memory into a register for the last two accesses. php_var_serialize_string already does something similar.
1 parent 6c5942f commit f039bae

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

ext/standard/var.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -731,11 +731,11 @@ static inline bool php_var_serialize_class_name(smart_str *buf, zval *struc) /*
731731
char b[32], *s, *res;
732732
size_t l, new_len;
733733
PHP_CLASS_ATTRIBUTES;
734-
735734
PHP_SET_CLASS_ATTRIBUTES(struc);
736-
s = zend_print_long_to_buf(b + sizeof(b) - 1, ZSTR_LEN(class_name));
735+
size_t class_name_len = ZSTR_LEN(class_name);
736+
s = zend_print_long_to_buf(b + sizeof(b) - 1, class_name_len);
737737
l = b + sizeof(b) - 1 - s;
738-
new_len = smart_str_alloc(buf, 2 + l + 2 + ZSTR_LEN(class_name) + 2, 0);
738+
new_len = smart_str_alloc(buf, 2 + l + 2 + class_name_len + 2, 0);
739739
res = ZSTR_VAL(buf->s) + ZSTR_LEN(buf->s);
740740
ZSTR_LEN(buf->s) = new_len;
741741
memcpy(res, "O:", 2);
@@ -744,8 +744,8 @@ static inline bool php_var_serialize_class_name(smart_str *buf, zval *struc) /*
744744
res += l;
745745
memcpy(res, ":\"", 2);
746746
res += 2;
747-
memcpy(res, ZSTR_VAL(class_name), ZSTR_LEN(class_name));
748-
res += ZSTR_LEN(class_name);
747+
memcpy(res, ZSTR_VAL(class_name), class_name_len);
748+
res += class_name_len;
749749
memcpy(res, "\":", 2);
750750
PHP_CLEANUP_CLASS_ATTRIBUTES();
751751
return incomplete_class;

0 commit comments

Comments
 (0)