@@ -1218,28 +1218,50 @@ PHPAPI void php_implode(const zend_string *delim, zval *arr, zval *return_value)
1218
1218
} ZEND_HASH_FOREACH_END ();
1219
1219
}
1220
1220
1221
- strings = emalloc (sizeof (zend_string * ) * numelems );
1221
+ strings = emalloc (( sizeof (zend_long ) + sizeof ( zend_string * ) ) * numelems );
1222
1222
strptr = strings - 1 ;
1223
1223
1224
1224
ZEND_HASH_FOREACH_VAL (Z_ARRVAL_P (arr ), tmp ) {
1225
- * ++ strptr = zval_get_string (tmp );
1226
- len += (* strptr )-> len ;
1225
+ if (Z_TYPE_P (tmp ) == IS_LONG ) {
1226
+ * ++ strptr = NULL ;
1227
+ ((zend_long * ) (strings + numelems ))[strptr - strings ] = Z_LVAL_P (tmp );
1228
+ len += (int ) log10 (Z_LVAL_P (tmp ) < 0 ? -100 * ((double ) Z_LVAL_P (tmp ) - 0.001 ) : 10 * ((double ) Z_LVAL_P (tmp ) + 0.01 ));
1229
+ } else {
1230
+ * ++ strptr = zval_get_string (tmp );
1231
+ len += (* strptr )-> len ;
1232
+ }
1227
1233
} ZEND_HASH_FOREACH_END ();
1228
1234
1229
1235
str = zend_string_alloc (len + (numelems - 1 ) * delim -> len , 0 );
1230
1236
cptr = str -> val + str -> len ;
1231
1237
* cptr = 0 ;
1232
1238
1233
1239
do {
1234
- cptr -= (* strptr )-> len ;
1235
- memcpy (cptr , (* strptr )-> val , (* strptr )-> len );
1236
- zend_string_release (* strptr );
1240
+ if (* strptr ) {
1241
+ cptr -= (* strptr )-> len ;
1242
+ memcpy (cptr , (* strptr )-> val , (* strptr )-> len );
1243
+ zend_string_release (* strptr );
1244
+ } else {
1245
+ char * oldPtr = cptr ;
1246
+ char oldVal = * cptr ;
1247
+ zend_long val = ((zend_long * ) (strings + numelems ))[strptr - strings ];
1248
+ cptr = zend_print_long_to_buf (cptr , val );
1249
+ * oldPtr = oldVal ;
1250
+ }
1237
1251
1238
1252
cptr -= delim -> len ;
1239
1253
memcpy (cptr , delim -> val , delim -> len );
1240
1254
} while (-- strptr > strings );
1241
- memcpy (str -> val , (* strptr )-> val , (* strptr )-> len );
1242
- zend_string_release (* strptr );
1255
+
1256
+ if (* strptr ) {
1257
+ memcpy (str -> val , (* strptr )-> val , (* strptr )-> len );
1258
+ zend_string_release (* strptr );
1259
+ } else {
1260
+ char * oldPtr = cptr ;
1261
+ char oldVal = * cptr ;
1262
+ zend_print_long_to_buf (cptr , ((zend_long * ) (strings + numelems ))[strptr - strings ]);
1263
+ * oldPtr = oldVal ;
1264
+ }
1243
1265
1244
1266
efree (strings );
1245
1267
RETURN_NEW_STR (str );
0 commit comments