Skip to content

Commit 29c7ee4

Browse files
Add a 1-char fastpath to implode() (php#19276)
1 parent 22d002e commit 29c7ee4

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

ext/standard/string.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,11 @@ PHPAPI void php_implode(const zend_string *glue, HashTable *pieces, zval *return
10261026
}
10271027

10281028
cptr -= ZSTR_LEN(glue);
1029-
memcpy(cptr, ZSTR_VAL(glue), ZSTR_LEN(glue));
1029+
if (ZSTR_LEN(glue) == 1) {
1030+
*cptr = ZSTR_VAL(glue)[0];
1031+
} else {
1032+
memcpy(cptr, ZSTR_VAL(glue), ZSTR_LEN(glue));
1033+
}
10301034
}
10311035

10321036
free_alloca(strings, use_heap);

0 commit comments

Comments
 (0)