mirror of
https://github.com/php/php-src.git
synced 2025-08-19 08:49:28 +02:00
have implode use the smart_str_*() functions, this should speed things up
quite a bit...
This commit is contained in:
parent
1fe42e10b7
commit
df837e67c7
1 changed files with 15 additions and 29 deletions
|
@ -818,42 +818,28 @@ PHP_FUNCTION(explode)
|
||||||
*/
|
*/
|
||||||
PHPAPI void php_implode(zval *delim, zval *arr, zval *return_value)
|
PHPAPI void php_implode(zval *delim, zval *arr, zval *return_value)
|
||||||
{
|
{
|
||||||
zval **tmp;
|
zval **tmp;
|
||||||
char *tmp_str;
|
HashPosition pos;
|
||||||
int len = 0, count = 0, target = 0;
|
smart_str implstr = {0};
|
||||||
HashPosition pos;
|
int numelems, i = 0;
|
||||||
|
|
||||||
|
numelems = zend_hash_num_elements(Z_ARRVAL_P(arr));
|
||||||
|
|
||||||
/* convert everything to strings, and calculate length */
|
|
||||||
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(arr), &pos);
|
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(arr), &pos);
|
||||||
while (zend_hash_get_current_data_ex(Z_ARRVAL_P(arr), (void **) &tmp, &pos) == SUCCESS) {
|
while (zend_hash_get_current_data_ex(Z_ARRVAL_P(arr),
|
||||||
|
(void **) &tmp,
|
||||||
|
&pos) == SUCCESS) {
|
||||||
convert_to_string_ex(tmp);
|
convert_to_string_ex(tmp);
|
||||||
len += Z_STRLEN_PP(tmp);
|
|
||||||
if (count > 0) {
|
|
||||||
len += Z_STRLEN_P(delim);
|
|
||||||
}
|
|
||||||
|
|
||||||
count++;
|
smart_str_appendl(&implstr, Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp));
|
||||||
zend_hash_move_forward_ex(Z_ARRVAL_P(arr), &pos);
|
if (++i != numelems) {
|
||||||
}
|
smart_str_appendl(&implstr, Z_STRVAL_P(delim), Z_STRLEN_P(delim));
|
||||||
|
|
||||||
/* do it */
|
|
||||||
tmp_str = (char *) emalloc(len + 1);
|
|
||||||
tmp_str[0] = 0;
|
|
||||||
|
|
||||||
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(arr), &pos);
|
|
||||||
while (zend_hash_get_current_data_ex(Z_ARRVAL_P(arr), (void **) &tmp, &pos) == SUCCESS) {
|
|
||||||
count--;
|
|
||||||
memcpy(tmp_str + target, Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp));
|
|
||||||
target += Z_STRLEN_PP(tmp);
|
|
||||||
if (count > 0) {
|
|
||||||
memcpy(tmp_str + target, Z_STRVAL_P(delim), Z_STRLEN_P(delim));
|
|
||||||
target += Z_STRLEN_P(delim);
|
|
||||||
}
|
}
|
||||||
zend_hash_move_forward_ex(Z_ARRVAL_P(arr), &pos);
|
zend_hash_move_forward_ex(Z_ARRVAL_P(arr), &pos);
|
||||||
}
|
}
|
||||||
tmp_str[len] = 0;
|
smart_str_0(&implstr);
|
||||||
|
|
||||||
RETURN_STRINGL(tmp_str, len, 0);
|
RETURN_STRINGL(implstr.c, implstr.len, 0);
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue