diff --git a/Antlr4.Runtime/Atn/SemanticContext.cs b/Antlr4.Runtime/Atn/SemanticContext.cs index 80a274d51..4e5b5d72a 100644 --- a/Antlr4.Runtime/Atn/SemanticContext.cs +++ b/Antlr4.Runtime/Atn/SemanticContext.cs @@ -386,27 +386,13 @@ namespace Antlr4.Runtime.Atn } private static IList FilterPrecedencePredicates - <_T0>(ICollection<_T0> collection) where _T0:SemanticContext + (ISet collection) { - List result = null; - for (IEnumerator iterator = collection.GetEnumerator(); iterator - .HasNext(); ) - { - SemanticContext context = iterator.Next(); - if (context is SemanticContext.PrecedencePredicate) - { - if (result == null) - { - result = new List(); - } - result.Add((SemanticContext.PrecedencePredicate)context); - iterator.Remove(); - } - } - if (result == null) - { - return Collections.EmptyList(); - } + if (!collection.OfType().Any()) + Collections.EmptyList(); + + List result = collection.OfType().ToList(); + collection.ExceptWith(result); return result; } }