clarity-pattern-parser 10.0.7 → 10.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -784,6 +784,7 @@
784
784
  this._name = name;
785
785
  this._parent = null;
786
786
  this._pattern = null;
787
+ this._cachedPattern = null;
787
788
  this._children = [];
788
789
  }
789
790
  test(text) {
@@ -805,7 +806,13 @@
805
806
  }
806
807
  _getPatternSafely() {
807
808
  if (this._pattern === null) {
808
- const pattern = this._findPattern();
809
+ let pattern = null;
810
+ if (this._cachedPattern == null) {
811
+ pattern = this._findPattern();
812
+ }
813
+ else {
814
+ pattern = this._cachedPattern;
815
+ }
809
816
  if (pattern === null) {
810
817
  throw new Error(`Couldn't find '${this._name}' pattern within tree.`);
811
818
  }
@@ -871,6 +878,10 @@
871
878
  clone(name = this._name) {
872
879
  const clone = new Reference(name);
873
880
  clone._id = this._id;
881
+ // Optimize future clones, by caching the pattern we already found.
882
+ if (this._pattern != null) {
883
+ clone._cachedPattern = this._pattern;
884
+ }
874
885
  return clone;
875
886
  }
876
887
  isEqual(pattern) {