Splice tree only when needed

This commit is contained in:
Andrea Marco Sartori 2023-02-01 19:15:37 +10:00
parent 6710ef4415
commit 49a315d22c

View File

@ -2,9 +2,6 @@
namespace Cerbero\JsonParser;
use function is_int;
use function is_string;
/**
* The JSON tree.
*
@ -94,9 +91,6 @@ final class Tree
$this->original[$this->depth] = $trimmedKey;
$this->wildcarded[$this->depth] = $trimmedKey;
array_splice($this->original, $this->depth + 1);
array_splice($this->wildcarded, $this->depth + 1);
}
/**
@ -113,9 +107,11 @@ final class Tree
$this->original[$this->depth] = is_int($index) ? $index + 1 : 0;
$this->wildcarded[$this->depth] = $referenceToken == '-' ? '-' : $this->original[$this->depth];
if (count($this->original) > $this->depth) {
array_splice($this->original, $this->depth + 1);
array_splice($this->wildcarded, $this->depth + 1);
}
}
/**
* Retrieve the current key