16
16
*/
17
17
class VarCloner extends AbstractCloner
18
18
{
19
+ private static $ gid ;
19
20
private static $ hashMask = 0 ;
20
21
private static $ hashOffset = 0 ;
22
+ private static $ arrayCache = array (
23
+ Stub::ARRAY_ASSOC => array (),
24
+ Stub::ARRAY_INDEXED => array (),
25
+ );
21
26
22
27
/**
23
28
* {@inheritdoc}
@@ -36,14 +41,15 @@ protected function doClone($var)
36
41
$ maxItems = $ this ->maxItems ;
37
42
$ maxString = $ this ->maxString ;
38
43
$ cookie = (object ) array (); // Unique object used to detect hard references
39
- $ gid = uniqid (mt_rand (), true ); // Unique string used to detect the special $GLOBALS variable
40
44
$ a = null ; // Array cast for nested structures
41
45
$ stub = null ; // Stub capturing the main properties of an original item value
42
46
// or null if the original value is used directly
43
47
44
48
if (!self ::$ hashMask ) {
49
+ self ::$ gid = uniqid (mt_rand (), true ); // Unique string used to detect the special $GLOBALS variable
45
50
self ::initHashMask ();
46
51
}
52
+ $ gid = self ::$ gid ;
47
53
$ hashMask = self ::$ hashMask ;
48
54
$ hashOffset = self ::$ hashOffset ;
49
55
$ arrayStub = new Stub ();
@@ -149,8 +155,6 @@ protected function doClone($var)
149
155
} else {
150
156
$ indexedArrays [$ len ] = true ;
151
157
}
152
-
153
- $ stub ->value = \count ($ a );
154
158
break ;
155
159
156
160
case \is_object ($ v ):
@@ -234,8 +238,10 @@ protected function doClone($var)
234
238
if ($ arrayStub ->cut ) {
235
239
$ stub = array ($ arrayStub ->cut , $ arrayStub ->class => $ arrayStub ->position );
236
240
$ arrayStub ->cut = 0 ;
241
+ } elseif (isset (self ::$ arrayCache [$ arrayStub ->class ][$ arrayStub ->position ])) {
242
+ $ stub = self ::$ arrayCache [$ arrayStub ->class ][$ arrayStub ->position ];
237
243
} else {
238
- $ stub = array ($ arrayStub ->class => $ arrayStub ->position );
244
+ self :: $ arrayCache [ $ arrayStub -> class ][ $ arrayStub -> position ] = $ stub = array ($ arrayStub ->class => $ arrayStub ->position );
239
245
}
240
246
}
241
247
0 commit comments