From 19a6b57fa5a3b3a46e10407b04f1b2d03c718799 Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Mon, 28 Jul 2025 14:02:28 +0200 Subject: [PATCH] Add a 1-char fastpath to `implode()` --- 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 a5acb28ddb3b..fffd796d94a8 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);