Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7f94d7e

Browse filesBrowse files
[DI] Keep and reuse array stubs in memory
1 parent dd9b5eb commit 7f94d7e
Copy full SHA for 7f94d7e

File tree

Expand file treeCollapse file tree

1 file changed

+10
-4
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+10
-4
lines changed

‎src/Symfony/Component/VarDumper/Cloner/VarCloner.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Cloner/VarCloner.php
+10-4Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,13 @@
1616
*/
1717
class VarCloner extends AbstractCloner
1818
{
19+
private static $gid;
1920
private static $hashMask = 0;
2021
private static $hashOffset = 0;
22+
private static $arrayCache = array(
23+
Stub::ARRAY_ASSOC => array(),
24+
Stub::ARRAY_INDEXED => array(),
25+
);
2126

2227
/**
2328
* {@inheritdoc}
@@ -36,14 +41,15 @@ protected function doClone($var)
3641
$maxItems = $this->maxItems;
3742
$maxString = $this->maxString;
3843
$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
4044
$a = null; // Array cast for nested structures
4145
$stub = null; // Stub capturing the main properties of an original item value
4246
// or null if the original value is used directly
4347

4448
if (!self::$hashMask) {
49+
self::$gid = uniqid(mt_rand(), true); // Unique string used to detect the special $GLOBALS variable
4550
self::initHashMask();
4651
}
52+
$gid = self::$gid;
4753
$hashMask = self::$hashMask;
4854
$hashOffset = self::$hashOffset;
4955
$arrayStub = new Stub();
@@ -149,8 +155,6 @@ protected function doClone($var)
149155
} else {
150156
$indexedArrays[$len] = true;
151157
}
152-
153-
$stub->value = \count($a);
154158
break;
155159

156160
case \is_object($v):
@@ -234,8 +238,10 @@ protected function doClone($var)
234238
if ($arrayStub->cut) {
235239
$stub = array($arrayStub->cut, $arrayStub->class => $arrayStub->position);
236240
$arrayStub->cut = 0;
241+
} elseif (isset(self::$arrayCache[$arrayStub->class][$arrayStub->position])) {
242+
$stub = self::$arrayCache[$arrayStub->class][$arrayStub->position];
237243
} else {
238-
$stub = array($arrayStub->class => $arrayStub->position);
244+
self::$arrayCache[$arrayStub->class][$arrayStub->position] = $stub = array($arrayStub->class => $arrayStub->position);
239245
}
240246
}
241247

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.