26
26
*/
27
27
package com .inet .lib .less ;
28
28
29
+ import java .util .ArrayDeque ;
29
30
import java .util .Arrays ;
30
31
import java .util .LinkedHashSet ;
31
32
import java .util .List ;
@@ -42,6 +43,15 @@ class LessExtendMap {
42
43
// use a LinkedHashSet as cache to remove duplicates and hold the original order
43
44
private final LinkedHashSet <String > selectorList = new LinkedHashSet <>();
44
45
46
+ private final ArrayDeque <SelectorTokenizer > tokenizers = new ArrayDeque <SelectorTokenizer >() {
47
+ public SelectorTokenizer pollLast () {
48
+ if ( size () == 0 ) {
49
+ return new SelectorTokenizer ();
50
+ }
51
+ return super .pollLast ();
52
+ }
53
+ };
54
+
45
55
/**
46
56
* Default constructor
47
57
*/
@@ -75,14 +85,15 @@ void add( LessExtend lessExtend, String[] mainSelector ) {
75
85
String extendingSelector = lessExtend .getExtendingSelector ();
76
86
if ( lessExtend .isAll () ) {
77
87
LessExtendResult extend = new LessExtendResult ( mainSelector , extendingSelector );
78
- SelectorTokenizer tokenizer = new SelectorTokenizer ( extendingSelector );
88
+ SelectorTokenizer tokenizer = tokenizers . pollLast (). init ( extendingSelector );
79
89
do {
80
90
String token = tokenizer .next ();
81
91
if ( token == null ) {
82
92
break ;
83
93
}
84
94
all .add ( token , extend );
85
95
} while ( true );
96
+ tokenizers .addLast ( tokenizer );
86
97
} else {
87
98
exact .add ( extendingSelector , mainSelector );
88
99
}
@@ -145,7 +156,7 @@ private void concatenateExtendsRecursive( String selector, boolean isReference,
145
156
}
146
157
}
147
158
}
148
- SelectorTokenizer tokenizer = new SelectorTokenizer ( allSelector );
159
+ SelectorTokenizer tokenizer = tokenizers . pollLast (). init ( allSelector );
149
160
do {
150
161
String token = tokenizer .next ();
151
162
if ( token == null ) {
@@ -167,5 +178,6 @@ private void concatenateExtendsRecursive( String selector, boolean isReference,
167
178
}
168
179
}
169
180
} while ( true );
181
+ tokenizers .addLast ( tokenizer );
170
182
}
171
183
}
0 commit comments