LUCENE-937: CachingTokenFilter now uses an iterator to access the Tokens that are cached in the LinkedList.

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@550060 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Busch 2007-06-23 15:56:34 +00:00
parent ced5990707
commit 7505950c5f
2 changed files with 13 additions and 4 deletions

View File

@ -14,6 +14,11 @@ New features
Optimizations
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)
Documentation
Build

View File

@ -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 lazily
cache = new LinkedList();
fillCache();
iterator = cache.iterator();
}
if (index == cache.size()) {
if (!iterator.hasNext()) {
// the cache is exhausted, return null
return 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 {