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/07/24 19:04:29 UTC
[lucenenet] branch master updated (c73ffd1 -> a147f67)
This is an automated email from the ASF dual-hosted git repository.
nightowl888 pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/lucenenet.git.
from c73ffd1 PERFORMANCE: SWEEP: Replaced Substring method where appropriate with the overloads of number class Parse/TryParse that accept startIndex and length
new 0e4795f Lucene.Net.Analysis.Phonetic, Lucene.Net.TestFramework: Reduced dependency on Lucene.Net.Support.CollectionExtensions by calling ExceptWith instead of CollectionExtensions.RemoveAll()
new 0d9abf6 Lucene.Net.Support.CollectionExtensions: Made more efficient RemoveAll() method and added RetainAll() for use in rare circumstances when we want to do set actions on ICollection<T>
new a147f67 Lucene.Net.Benchmark: Use RetainAll() for better efficiency
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../Language/Bm/PhoneticEngine.cs | 10 +--
.../ByTask/Tasks/SearchTravRetHighlightTask.cs | 9 +--
.../Tasks/SearchTravRetVectorHighlightTask.cs | 9 +--
.../Store/MockDirectoryWrapper.cs | 2 +-
src/Lucene.Net/Support/CollectionExtensions.cs | 84 +++++++++++++++++++---
5 files changed, 84 insertions(+), 30 deletions(-)
[lucenenet] 01/03: Lucene.Net.Analysis.Phonetic,
Lucene.Net.TestFramework: Reduced dependency on
Lucene.Net.Support.CollectionExtensions by calling ExceptWith instead of
CollectionExtensions.RemoveAll()
Posted by ni...@apache.org.
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 0e4795f23e7297b6dc45c77395ef9be6ba6d2170
Author: Shad Storhaug <sh...@shadstorhaug.com>
AuthorDate: Sat Jul 24 15:44:38 2021 +0700
Lucene.Net.Analysis.Phonetic, Lucene.Net.TestFramework: Reduced dependency on Lucene.Net.Support.CollectionExtensions by calling ExceptWith instead of CollectionExtensions.RemoveAll()
---
src/Lucene.Net.Analysis.Phonetic/Language/Bm/PhoneticEngine.cs | 10 +++++-----
src/Lucene.Net.TestFramework/Store/MockDirectoryWrapper.cs | 2 +-
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/Lucene.Net.Analysis.Phonetic/Language/Bm/PhoneticEngine.cs b/src/Lucene.Net.Analysis.Phonetic/Language/Bm/PhoneticEngine.cs
index 4b1f945..6b6e360 100644
--- a/src/Lucene.Net.Analysis.Phonetic/Language/Bm/PhoneticEngine.cs
+++ b/src/Lucene.Net.Analysis.Phonetic/Language/Bm/PhoneticEngine.cs
@@ -445,7 +445,7 @@ namespace Lucene.Net.Analysis.Phonetic.Language.Bm
}
IList<string> words = WHITESPACE.Split(input).TrimEnd();
- IList<string> words2 = new List<string>();
+ ISet<string> words2 = new JCG.HashSet<string>();
// special-case handling of word prefixes based upon the name type
switch (this.nameType)
@@ -457,14 +457,14 @@ namespace Lucene.Net.Analysis.Phonetic.Language.Bm
string lastPart = parts[parts.Length - 1];
words2.Add(lastPart);
}
- words2.RemoveAll(NAME_PREFIXES[this.nameType]);
+ words2.ExceptWith(NAME_PREFIXES[this.nameType]);
break;
case NameType.ASHKENAZI:
- words2.AddRange(words);
- words2.RemoveAll(NAME_PREFIXES[this.nameType]);
+ words2.UnionWith(words);
+ words2.ExceptWith(NAME_PREFIXES[this.nameType]);
break;
case NameType.GENERIC:
- words2.AddRange(words);
+ words2.UnionWith(words);
break;
default:
throw new InvalidOperationException("Unreachable case: " + this.nameType);
diff --git a/src/Lucene.Net.TestFramework/Store/MockDirectoryWrapper.cs b/src/Lucene.Net.TestFramework/Store/MockDirectoryWrapper.cs
index 51319e7..e091f0d 100644
--- a/src/Lucene.Net.TestFramework/Store/MockDirectoryWrapper.cs
+++ b/src/Lucene.Net.TestFramework/Store/MockDirectoryWrapper.cs
@@ -255,7 +255,7 @@ namespace Lucene.Net.Store
}
else
{
- unSyncedFiles.RemoveAll(names);
+ unSyncedFiles.ExceptWith(names);
}
}
}
[lucenenet] 03/03: Lucene.Net.Benchmark: Use RetainAll() for better
efficiency
Posted by ni...@apache.org.
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 a147f676acc3526056a10dec08ad2bb029267d03
Author: Shad Storhaug <sh...@shadstorhaug.com>
AuthorDate: Fri Jul 23 13:07:27 2021 +0700
Lucene.Net.Benchmark: Use RetainAll() for better efficiency
---
.../ByTask/Tasks/SearchTravRetHighlightTask.cs | 9 +--------
.../ByTask/Tasks/SearchTravRetVectorHighlightTask.cs | 9 +--------
2 files changed, 2 insertions(+), 16 deletions(-)
diff --git a/src/Lucene.Net.Benchmark/ByTask/Tasks/SearchTravRetHighlightTask.cs b/src/Lucene.Net.Benchmark/ByTask/Tasks/SearchTravRetHighlightTask.cs
index 19a5af5..1f54d9b 100644
--- a/src/Lucene.Net.Benchmark/ByTask/Tasks/SearchTravRetHighlightTask.cs
+++ b/src/Lucene.Net.Benchmark/ByTask/Tasks/SearchTravRetHighlightTask.cs
@@ -122,14 +122,7 @@ namespace Lucene.Net.Benchmarks.ByTask.Tasks
//if stored is false, then result will be empty, in which case just get all the param fields
if (m_paramFields.Count > 0 && result.Count > 0)
{
- //result.RetainAll(paramFields);
- var toRemove = new List<string>();
- foreach (var e in result)
- {
- if (!m_paramFields.Contains(e))
- toRemove.Add(e);
- }
- result.RemoveAll(toRemove);
+ result.RetainAll(m_paramFields);
}
else
{
diff --git a/src/Lucene.Net.Benchmark/ByTask/Tasks/SearchTravRetVectorHighlightTask.cs b/src/Lucene.Net.Benchmark/ByTask/Tasks/SearchTravRetVectorHighlightTask.cs
index b898bc0..52afa31 100644
--- a/src/Lucene.Net.Benchmark/ByTask/Tasks/SearchTravRetVectorHighlightTask.cs
+++ b/src/Lucene.Net.Benchmark/ByTask/Tasks/SearchTravRetVectorHighlightTask.cs
@@ -126,14 +126,7 @@ namespace Lucene.Net.Benchmarks.ByTask.Tasks
//if stored is false, then result will be empty, in which case just get all the param fields
if (m_paramFields.Count > 0 && result.Count > 0)
{
- //result.RetainAll(paramFields);
- var toRemove = new List<string>();
- foreach (var e in result)
- {
- if (!m_paramFields.Contains(e))
- toRemove.Add(e);
- }
- result.RemoveAll(toRemove);
+ result.RetainAll(m_paramFields);
}
else
{
[lucenenet] 02/03: Lucene.Net.Support.CollectionExtensions: Made
more efficient RemoveAll() method and added RetainAll() for use in rare
circumstances when we want to do set actions on ICollection
Posted by ni...@apache.org.
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 0d9abf64c4eb8d3867254bc7f60c4ef1367b3b90
Author: Shad Storhaug <sh...@shadstorhaug.com>
AuthorDate: Fri Jul 23 13:06:43 2021 +0700
Lucene.Net.Support.CollectionExtensions: Made more efficient RemoveAll() method and added RetainAll() for use in rare circumstances when we want to do set actions on ICollection<T>
---
src/Lucene.Net/Support/CollectionExtensions.cs | 84 +++++++++++++++++++++++---
1 file changed, 76 insertions(+), 8 deletions(-)
diff --git a/src/Lucene.Net/Support/CollectionExtensions.cs b/src/Lucene.Net/Support/CollectionExtensions.cs
index 6eb7ed0..12c9f70 100644
--- a/src/Lucene.Net/Support/CollectionExtensions.cs
+++ b/src/Lucene.Net/Support/CollectionExtensions.cs
@@ -1,7 +1,8 @@
-using System;
+using J2N.Collections.Generic.Extensions;
+using System;
using System.Collections.Generic;
using System.Diagnostics;
-using System.Runtime.CompilerServices;
+using JCG = J2N.Collections.Generic;
namespace Lucene.Net.Support
{
@@ -29,23 +30,90 @@ namespace Lucene.Net.Support
{
/// <summary>
/// Removes the given collection of elements from the source <see cref="ICollection{T}"/>.
+ /// <para/>
+ /// Usage Note: This is the same operation as <see cref="ISet{T}.ExceptWith(IEnumerable{T})"/> or
+ /// <see cref="List{T}.RemoveAll(Predicate{T})"/> with a predicate of <c>(value) => collection.Contains(value)</c>. It is
+ /// recommended to use these alternatives when possible.
/// </summary>
/// <typeparam name="T">The type of the elements of <paramref name="source"/>.</typeparam>
/// <param name="source">An <see cref="ICollection{T}"/> to remove elements from.</param>
- /// <param name="removeList">An <see cref="IEnumerable{T}"/> containing the items to remove from <paramref name="source"/>.</param>
+ /// <param name="collection">An <see cref="ICollection{T}"/> containing the items to remove from <paramref name="source"/>.</param>
+ /// <returns><c>true</c> if the collection changed as a result of the call; otherwise, <c>false</c>.</returns>
[DebuggerStepThrough]
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void RemoveAll<T>(this ICollection<T> source, IEnumerable<T> removeList)
+ public static bool RemoveAll<T>(this ICollection<T> source, ICollection<T> collection)
{
if (source == null)
throw new ArgumentNullException(nameof(source));
+ if (collection == null)
+ throw new ArgumentNullException(nameof(collection));
- if (source.Count == 0) return;
+ if (source.Count == 0) return false;
- foreach (var elt in removeList)
+ if (source is ISet<T> set)
{
- source.Remove(elt);
+ int originalCount = set.Count;
+ set.ExceptWith(collection);
+ return originalCount != set.Count;
}
+ else if (source is IList<T> list)
+ {
+ int removed = list.RemoveAll((value) => collection.Contains(value));
+ return removed > 0;
+ }
+
+ // Slow path for unknown collection types
+ bool modified = false;
+ foreach (var e in collection)
+ {
+ modified |= source.Remove(e);
+ }
+ return modified;
+ }
+
+ /// <summary>
+ /// Retains only the elements in this list that are contained in the specified collection (optional operation).
+ /// In other words, removes from this list all of its elements that are not contained in the specified collection.
+ /// <para/>
+ /// Usage Note: This is the same operation as <see cref="ISet{T}.IntersectWith(IEnumerable{T})"/> or
+ /// <see cref="List{T}.RemoveAll(Predicate{T})"/> with a predicate of <c>(value) => !collection.Contains(value)</c>. It is
+ /// recommended to use these alternatives when possible.
+ /// </summary>
+ /// <typeparam name="T">The type of the elements of <paramref name="source"/>.</typeparam>
+ /// <param name="source">An <see cref="ICollection{T}"/> to remove elements from.</param>
+ /// <param name="collection">An <see cref="ICollection{T}"/> containing the items to remove from <paramref name="source"/>.</param>
+ /// <returns><c>true</c> if the collection changed as a result of the call; otherwise, <c>false</c>.</returns>
+ [DebuggerStepThrough]
+ public static bool RetainAll<T>(this ICollection<T> source, ICollection<T> collection)
+ {
+ if (source == null)
+ throw new ArgumentNullException(nameof(source));
+ if (collection == null)
+ throw new ArgumentNullException(nameof(collection));
+
+ if (source.Count == 0) return false;
+
+ if (source is ISet<T> set)
+ {
+ int originalCount = set.Count;
+ set.IntersectWith(collection);
+ return originalCount != set.Count;
+ }
+ else if (source is IList<T> list)
+ {
+ int removed = list.RemoveAll((value) => !collection.Contains(value));
+ return removed > 0;
+ }
+
+ // Slow path for unknown collection types
+ var toRemove = new JCG.HashSet<T>();
+ foreach (var e in source)
+ {
+ if (!collection.Contains(e))
+ toRemove.Add(e);
+ }
+ if (toRemove.Count > 0)
+ return source.RemoveAll(toRemove);
+ return false;
}
}
}