Mercurial > hg > isophonics-drupal-site
diff vendor/sebastian/recursion-context/src/Context.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | 4c8ae668cc8c |
children |
line wrap: on
line diff
--- a/vendor/sebastian/recursion-context/src/Context.php Mon Apr 23 09:33:26 2018 +0100 +++ b/vendor/sebastian/recursion-context/src/Context.php Mon Apr 23 09:46:53 2018 +0100 @@ -92,9 +92,27 @@ return $key; } + $key = count($this->arrays); $this->arrays[] = &$array; - return count($this->arrays) - 1; + if (!isset($array[PHP_INT_MAX]) && !isset($array[PHP_INT_MAX - 1])) { + $array[] = $key; + $array[] = $this->objects; + } else { /* cover the improbable case too */ + do { + $key = random_int(PHP_INT_MIN, PHP_INT_MAX); + } while (isset($array[$key])); + + $array[$key] = $key; + + do { + $key = random_int(PHP_INT_MIN, PHP_INT_MAX); + } while (isset($array[$key])); + + $array[$key] = $this->objects; + } + + return $key; } /** @@ -118,22 +136,9 @@ */ private function containsArray(array &$array) { - $keys = array_keys($this->arrays, $array, true); - $hash = '_Key_' . microtime(true); + $end = array_slice($array, -2); - foreach ($keys as $key) { - $this->arrays[$key][$hash] = $hash; - - if (isset($array[$hash]) && $array[$hash] === $hash) { - unset($this->arrays[$key][$hash]); - - return $key; - } - - unset($this->arrays[$key][$hash]); - } - - return false; + return isset($end[1]) && $end[1] === $this->objects ? $end[0] : false; } /** @@ -149,4 +154,14 @@ return false; } + + public function __destruct() + { + foreach ($this->arrays as &$array) { + if (is_array($array)) { + array_pop($array); + array_pop($array); + } + } + } }