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.
@@ -7,6 +7,7 @@ export declare class Reference implements Pattern {
7
7
  private _type;
8
8
  private _name;
9
9
  private _parent;
10
+ private _cachedPattern;
10
11
  private _pattern;
11
12
  private _children;
12
13
  get id(): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clarity-pattern-parser",
3
- "version": "10.0.7",
3
+ "version": "10.0.8",
4
4
  "description": "Parsing Library for Typescript and Javascript.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.esm.js",
@@ -11,6 +11,7 @@ export class Reference implements Pattern {
11
11
  private _type: string;
12
12
  private _name: string;
13
13
  private _parent: Pattern | null;
14
+ private _cachedPattern: Pattern | null;
14
15
  private _pattern: Pattern | null;
15
16
  private _children: Pattern[];
16
17
 
@@ -44,6 +45,7 @@ export class Reference implements Pattern {
44
45
  this._name = name;
45
46
  this._parent = null;
46
47
  this._pattern = null;
48
+ this._cachedPattern = null;
47
49
  this._children = [];
48
50
  }
49
51
 
@@ -72,7 +74,13 @@ export class Reference implements Pattern {
72
74
 
73
75
  private _getPatternSafely(): Pattern {
74
76
  if (this._pattern === null) {
75
- const pattern = this._findPattern();
77
+ let pattern: Pattern | null = null;
78
+
79
+ if (this._cachedPattern == null) {
80
+ pattern = this._findPattern();
81
+ } else {
82
+ pattern = this._cachedPattern;
83
+ }
76
84
 
77
85
  if (pattern === null) {
78
86
  throw new Error(`Couldn't find '${this._name}' pattern within tree.`);
@@ -159,6 +167,12 @@ export class Reference implements Pattern {
159
167
  clone(name = this._name): Pattern {
160
168
  const clone = new Reference(name);
161
169
  clone._id = this._id;
170
+
171
+ // Optimize future clones, by caching the pattern we already found.
172
+ if (this._pattern != null) {
173
+ clone._cachedPattern = this._pattern;
174
+ }
175
+
162
176
  return clone;
163
177
  }
164
178