Skip to content

Commit 8ff7456

Browse files
committed
Optimize OWLExpressionHelper.RemoveDuplicates
1 parent 6aafc8f commit 8ff7456

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

OWLSharp/Ontology/Expressions/OWLExpressionHelper.cs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,21 @@ public static T ToEntity<T>(this RDFResource iri) where T : IOWLEntity
6060
/// </summary>
6161
internal static List<T> RemoveDuplicates<T>(List<T> expressions) where T : OWLExpression
6262
{
63-
List<T> deduplicatedExpressions = new List<T>();
64-
if (expressions?.Count > 0)
63+
#region Guards
64+
if (expressions == null || expressions.Count == 0)
65+
return new List<T>();
66+
#endregion
67+
68+
#if NET8_0_OR_GREATER
69+
HashSet<long> lookup = new HashSet<long>(expressions.Count);
70+
#else
71+
HashSet<long> lookup = new HashSet<long>();
72+
#endif
73+
List<T> deduplicatedExpressions = new List<T>(expressions.Count);
74+
foreach (T expression in expressions)
6575
{
66-
HashSet<long> lookup = new HashSet<long>();
67-
expressions.ForEach(expression =>
68-
{
69-
long expressionID = expression.GetIRI().PatternMemberID;
70-
if (lookup.Add(expressionID))
71-
deduplicatedExpressions.Add(expression);
72-
});
76+
if (lookup.Add(expression.GetIRI().PatternMemberID))
77+
deduplicatedExpressions.Add(expression);
7378
}
7479
return deduplicatedExpressions;
7580
}

0 commit comments

Comments
 (0)