Apache Solr open-source search software
LUCENE-937: CachingTokenFilter now uses an iterator to access the Tokens that are cached in the LinkedList.
Michael Busch7505950c5fee
diff --git a/CHANGES.txt b/CHANGES.txtindex d05f25d29d7..22e5a915aaf 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -14,6 +14,11 @@ New featuresOptimizations+ 1. LUCENE-937: CachingTokenFilter now uses an iterator to access the+ Tokens that are cached in the LinkedList. This increases performance+ significantly, especially when the number of Tokens is large.+ (Mark Miller via Michael Busch)+DocumentationBuilddiff --git a/src/java/org/apache/lucene/analysis/CachingTokenFilter.java b/src/java/org/apache/lucene/analysis/CachingTokenFilter.javaindex c49729eca22..c35011d09eb 100644--- a/src/java/org/apache/lucene/analysis/CachingTokenFilter.java+++ b/src/java/org/apache/lucene/analysis/CachingTokenFilter.java@@ -18,6 +18,7 @@ package org.apache.lucene.analysis;*/import java.io.IOException;+import java.util.Iterator;import java.util.LinkedList;import java.util.List;@@ -33,7 +34,7 @@ import java.util.List;*/public class CachingTokenFilter extends TokenFilter {private List cache;- private int index;+ private Iterator iterator;public CachingTokenFilter(TokenStream input) {super(input);@@ -44,18 +45,21 @@ public class CachingTokenFilter extends TokenFilter {// fill cache lazilycache = new LinkedList();fillCache();+ iterator = cache.iterator();}- if (index == cache.size()) {+ if (!iterator.hasNext()) {// the cache is exhausted, return nullreturn null;}- return (Token) cache.get(index++);+ return (Token) iterator.next();}public void reset() throws IOException {- index = 0;+ if(cache != null) {+ iterator = cache.iterator();+ }}private void fillCache() throws IOException {