This is an automated email from the ASF dual-hosted git repository. nightowl888 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/lucenenet.git
commit 8d5903360d41f25a8de2caaabf668a20bd456839 Author: Shad Storhaug <[email protected]> AuthorDate: Sat Jul 18 07:54:28 2020 +0700 PERFORMANCE: Lucene.Net.Analysis.Common: Changed the inputWindow in ShingleFilter to use a Queue instead of LinkedList --- .../Analysis/Shingle/ShingleFilter.cs | 26 +++++++++------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Shingle/ShingleFilter.cs b/src/Lucene.Net.Analysis.Common/Analysis/Shingle/ShingleFilter.cs index 5285413..147efe7 100644 --- a/src/Lucene.Net.Analysis.Common/Analysis/Shingle/ShingleFilter.cs +++ b/src/Lucene.Net.Analysis.Common/Analysis/Shingle/ShingleFilter.cs @@ -69,7 +69,7 @@ namespace Lucene.Net.Analysis.Shingle /// The sequence of input stream tokens (or filler tokens, if necessary) /// that will be composed to form output shingles. /// </summary> - private LinkedList<InputWindowToken> inputWindow = new LinkedList<InputWindowToken>(); + private readonly Queue<InputWindowToken> inputWindow = new Queue<InputWindowToken>(); /// <summary> /// The number of input tokens in the next output token. This is the "n" in @@ -80,7 +80,7 @@ namespace Lucene.Net.Analysis.Shingle /// <summary> /// Shingle and unigram text is composed here. /// </summary> - private StringBuilder gramBuilder = new StringBuilder(); + private readonly StringBuilder gramBuilder = new StringBuilder(); /// <summary> /// The token type attribute value to use - default is "shingle" @@ -296,7 +296,7 @@ namespace Lucene.Net.Analysis.Shingle /// <param name="tokenSeparator"> used to separate input stream tokens in output shingles </param> public void SetTokenSeparator(string tokenSeparator) { - this.tokenSeparator = null == tokenSeparator ? "" : tokenSeparator; + this.tokenSeparator = tokenSeparator ?? string.Empty; } /// <summary> @@ -363,7 +363,7 @@ namespace Lucene.Net.Analysis.Shingle } if (!isAllFiller && builtGramSize == gramSize.Value) { - inputWindow.First.Value.attSource.CopyTo(this); + inputWindow.Peek().attSource.CopyTo(this); posIncrAtt.PositionIncrement = isOutputHere ? 0 : 1; termAtt.SetEmpty().Append(gramBuilder); if (gramSize.Value > 1) @@ -401,7 +401,7 @@ namespace Lucene.Net.Analysis.Shingle { if (null == target) { - newTarget = new InputWindowToken(this, nextInputStreamToken.CloneAttributes()); + newTarget = new InputWindowToken(nextInputStreamToken.CloneAttributes()); } else { @@ -417,7 +417,7 @@ namespace Lucene.Net.Analysis.Shingle { if (null == target) { - newTarget = new InputWindowToken(this, nextInputStreamToken.CloneAttributes()); + newTarget = new InputWindowToken(nextInputStreamToken.CloneAttributes()); } else { @@ -432,7 +432,7 @@ namespace Lucene.Net.Analysis.Shingle { if (null == target) { - newTarget = new InputWindowToken(this, CloneAttributes()); + newTarget = new InputWindowToken(CloneAttributes()); } else { @@ -518,8 +518,7 @@ namespace Lucene.Net.Analysis.Shingle InputWindowToken firstToken = null; if (inputWindow.Count > 0) { - firstToken = inputWindow.First.Value; - inputWindow.Remove(firstToken); + firstToken = inputWindow.Dequeue(); } while (inputWindow.Count < maxShingleSize) { @@ -527,7 +526,7 @@ namespace Lucene.Net.Analysis.Shingle { if (null != GetNextToken(firstToken)) { - inputWindow.AddLast(firstToken); // the firstToken becomes the last + inputWindow.Enqueue(firstToken); // the firstToken becomes the last firstToken = null; } else @@ -540,7 +539,7 @@ namespace Lucene.Net.Analysis.Shingle InputWindowToken nextToken = GetNextToken(null); if (null != nextToken) { - inputWindow.AddLast(nextToken); + inputWindow.Enqueue(nextToken); } else { @@ -678,16 +677,13 @@ namespace Lucene.Net.Analysis.Shingle private class InputWindowToken { - private readonly ShingleFilter outerInstance; - internal readonly AttributeSource attSource; internal readonly ICharTermAttribute termAtt; internal readonly IOffsetAttribute offsetAtt; internal bool isFiller = false; - public InputWindowToken(ShingleFilter outerInstance, AttributeSource attSource) + public InputWindowToken(AttributeSource attSource) { - this.outerInstance = outerInstance; this.attSource = attSource; this.termAtt = attSource.GetAttribute<ICharTermAttribute>(); this.offsetAtt = attSource.GetAttribute<IOffsetAttribute>();
