You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ni...@apache.org on 2021/03/14 12:54:51 UTC
[lucenenet] 01/02: PERFORMANCE:
Lucene.Net.Search.Suggest.Fst.FSTCompletion: Use Stack rather than
List.Reverse(). Also,
removed unnecessary lock in CheckExistingAndReorder(),
as it is only used in a single thread at a time.
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 1fa93124ee701ed41b699b9717a420061725ee76
Author: Shad Storhaug <sh...@shadstorhaug.com>
AuthorDate: Sun Mar 14 16:35:20 2021 +0700
PERFORMANCE: Lucene.Net.Search.Suggest.Fst.FSTCompletion: Use Stack<T> rather than List<T>.Reverse(). Also, removed unnecessary lock in CheckExistingAndReorder(), as it is only used in a single thread at a time.
---
src/Lucene.Net.Suggest/Suggest/Fst/FSTCompletion.cs | 20 +++++++-------------
1 file changed, 7 insertions(+), 13 deletions(-)
diff --git a/src/Lucene.Net.Suggest/Suggest/Fst/FSTCompletion.cs b/src/Lucene.Net.Suggest/Suggest/Fst/FSTCompletion.cs
index 6cdc8a9..441f8b0 100644
--- a/src/Lucene.Net.Suggest/Suggest/Fst/FSTCompletion.cs
+++ b/src/Lucene.Net.Suggest/Suggest/Fst/FSTCompletion.cs
@@ -100,9 +100,6 @@ namespace Lucene.Net.Search.Suggest.Fst
/// <seealso cref="FSTCompletion(FST{object}, bool, bool)" />
private readonly bool higherWeightsFirst;
- // LUCENENET SPECIFIC: We need some thread safety to execute atomic list operations
- private readonly object syncLock = new object();
-
/// <summary>
/// Constructs an FSTCompletion, specifying higherWeightsFirst and exactFirst. </summary>
/// <param name="automaton">
@@ -146,13 +143,14 @@ namespace Lucene.Net.Search.Suggest.Fst
{
try
{
- List<FST.Arc<object>> rootArcs = new List<FST.Arc<object>>();
+ // LUCENENET specific: Using a stack rather than List, as we want the results in reverse
+ Stack<FST.Arc<object>> rootArcs = new Stack<FST.Arc<object>>();
FST.Arc<object> arc = automaton.GetFirstArc(new FST.Arc<object>());
FST.BytesReader fstReader = automaton.GetBytesReader();
automaton.ReadFirstTargetArc(arc, arc, fstReader);
while (true)
{
- rootArcs.Add((new FST.Arc<object>()).CopyFrom(arc));
+ rootArcs.Push(new FST.Arc<object>().CopyFrom(arc));
if (arc.IsLast)
{
break;
@@ -161,7 +159,6 @@ namespace Lucene.Net.Search.Suggest.Fst
}
// we want highest weights first.
- rootArcs.Reverse();
return rootArcs.ToArray();
}
catch (IOException e)
@@ -353,14 +350,11 @@ namespace Lucene.Net.Search.Suggest.Fst
// Key found. Unless already at i==0, remove it and push up front so
// that the ordering
// remains identical with the exception of the exact match.
- lock (syncLock)
+ if (key.Equals(list[i].Utf8))
{
- if (key.Equals(list[i].Utf8))
- {
- var element = list[i];
- list.Remove(element);
- list.Insert(0, element);
- }
+ var element = list[i];
+ list.Remove(element);
+ list.Insert(0, element);
}
return true;
}