diff --git a/src/com/inet/lib/less/LessExtendMap.java b/src/com/inet/lib/less/LessExtendMap.java index c341b141..4bb39906 100644 --- a/src/com/inet/lib/less/LessExtendMap.java +++ b/src/com/inet/lib/less/LessExtendMap.java @@ -26,6 +26,7 @@ */ package com.inet.lib.less; +import java.util.ArrayDeque; import java.util.Arrays; import java.util.LinkedHashSet; import java.util.List; @@ -42,6 +43,15 @@ class LessExtendMap { // use a LinkedHashSet as cache to remove duplicates and hold the original order private final LinkedHashSet selectorList = new LinkedHashSet<>(); + private final ArrayDeque tokenizers = new ArrayDeque() { + public SelectorTokenizer pollLast() { + if( size() == 0 ) { + return new SelectorTokenizer(); + } + return super.pollLast(); + } + }; + /** * Default constructor */ @@ -75,7 +85,7 @@ void add( LessExtend lessExtend, String[] mainSelector ) { String extendingSelector = lessExtend.getExtendingSelector(); if( lessExtend.isAll() ) { LessExtendResult extend = new LessExtendResult( mainSelector, extendingSelector ); - SelectorTokenizer tokenizer = new SelectorTokenizer( extendingSelector ); + SelectorTokenizer tokenizer = tokenizers.pollLast().init( extendingSelector ); do { String token = tokenizer.next(); if( token == null ) { @@ -83,6 +93,7 @@ void add( LessExtend lessExtend, String[] mainSelector ) { } all.add( token, extend ); } while( true ); + tokenizers.addLast( tokenizer ); } else { exact.add( extendingSelector, mainSelector ); } @@ -145,7 +156,7 @@ private void concatenateExtendsRecursive( String selector, boolean isReference, } } } - SelectorTokenizer tokenizer = new SelectorTokenizer( allSelector ); + SelectorTokenizer tokenizer = tokenizers.pollLast().init( allSelector ); do { String token = tokenizer.next(); if( token == null ) { @@ -167,5 +178,6 @@ private void concatenateExtendsRecursive( String selector, boolean isReference, } } } while( true ); + tokenizers.addLast( tokenizer ); } } diff --git a/src/com/inet/lib/less/SelectorTokenizer.java b/src/com/inet/lib/less/SelectorTokenizer.java index 894029ec..68bd398b 100644 --- a/src/com/inet/lib/less/SelectorTokenizer.java +++ b/src/com/inet/lib/less/SelectorTokenizer.java @@ -33,16 +33,18 @@ */ class SelectorTokenizer { - private final String selector; + private String selector; - private int idx, lastIdx; + private int idx, lastIdx; /** * Create a new tokenizer. * @param selector all selectors */ - SelectorTokenizer( String selector ) { + SelectorTokenizer init( String selector ) { this.selector = selector; + idx = lastIdx = 0; + return this; } /**