From 29c7ee4cd4621c9435574982884d9bc29ca02ae1 Mon Sep 17 00:00:00 2001 From: Alexandre Daubois <2144837+alexandre-daubois@users.noreply.github.com> Date: Wed, 10 Sep 2025 16:52:31 +0200 Subject: [PATCH] Add a 1-char fastpath to `implode()` (#19276) --- ext/standard/string.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ext/standard/string.c b/ext/standard/string.c index a5acb28ddb3..fffd796d94a 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -1026,7 +1026,11 @@ PHPAPI void php_implode(const zend_string *glue, HashTable *pieces, zval *return } cptr -= ZSTR_LEN(glue); - memcpy(cptr, ZSTR_VAL(glue), ZSTR_LEN(glue)); + if (ZSTR_LEN(glue) == 1) { + *cptr = ZSTR_VAL(glue)[0]; + } else { + memcpy(cptr, ZSTR_VAL(glue), ZSTR_LEN(glue)); + } } free_alloca(strings, use_heap);