]> granicus.if.org Git - php/commitdiff
Do not create a new array when slicing all of input array.
authorSara Golemon <pollita@php.net>
Fri, 27 Oct 2017 14:00:17 +0000 (10:00 -0400)
committerSara Golemon <pollita@php.net>
Fri, 27 Oct 2017 14:09:05 +0000 (10:09 -0400)
NEWS
ext/standard/array.c

diff --git a/NEWS b/NEWS
index 58b2e59ee090de0425e879381e88e579e7736827..ef0827faaf318b81d15d7b80ae9bcdd324a169ed 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -109,6 +109,8 @@ PHP                                                                        NEWS
 - Standard:
   . Fixed unzserialize(), to disable creation of unsupported data structures
     through manually crafted strings. (Dmitry)
+  . Short circuit case where array_slice() would return its original array.
+    (Sara, Benjamin Coutu)
 
 - Zlib:
   . Added zlib/level context option for compress.zlib wrapper. (Sara)
index 2a0053ee8b541a4377c1cd0521a957108856c7ed..89f0370461c22fd2d583e46ee28c8260d09ac004 100644 (file)
@@ -3563,6 +3563,14 @@ PHP_FUNCTION(array_slice)
                return;
        }
 
+       if ((offset == 0) && (length >= num_in) &&
+               HT_IS_PACKED(Z_ARRVAL_P(input)) &&
+               HT_IS_WITHOUT_HOLES(Z_ARRVAL_P(input))) {
+               /* No real slicing, and the keys will be 0..n-1, so just copy */
+               ZVAL_COPY(return_value, input);
+               return;
+       }
+
        /* Initialize returned array */
        array_init_size(return_value, (uint32_t)length);