Browse Source

Added cache for scope parsing

main
Dustin Wilson 3 years ago
parent
commit
cdc53456e0
  1. 11
      lib/Scope/Parser.php

11
lib/Scope/Parser.php

@ -8,6 +8,9 @@ namespace dW\Lit\Scope;
/** Parses scope strings into a matcher tree */
class Parser {
// Used to cache parsed scopes
protected static array $cache = [];
// When true prints out detailed data about the construction of the matcher
// tree.
public static bool $debug = false;
@ -34,8 +37,14 @@ class Parser {
* string.
*/
public static function parse(string $selector): Matcher|false {
if (isset(self::$cache[$selector])) {
return self::$cache[$selector];
}
self::$instance = new self($selector);
return self::parseSelector();
$result = self::parseSelector();
self::$cache[$selector] = $result;
return $result;
}

Loading…
Cancel
Save