From 52135aee0e6cf9cb109a88267fc41a5ba0253c51 Mon Sep 17 00:00:00 2001 From: Tahir KILIC Date: Fri, 2 Mar 2018 23:08:06 +0100 Subject: [PATCH] performance optimization in DFA.IsEmpty and DFA.IsContextSensitive. Both properties were calling DFAState.EdgeMap property which is returning a copy of the internal EdgeMap. Creating a copy is avoided by calling newly introduced DFAState.IsEdgeMapEmpty property. --- runtime/CSharp/Antlr4.Runtime/Dfa/DFA.cs | 4 ++-- runtime/CSharp/Antlr4.Runtime/Dfa/DFAState.cs | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/runtime/CSharp/Antlr4.Runtime/Dfa/DFA.cs b/runtime/CSharp/Antlr4.Runtime/Dfa/DFA.cs index 73d24452..8fb63316 100644 --- a/runtime/CSharp/Antlr4.Runtime/Dfa/DFA.cs +++ b/runtime/CSharp/Antlr4.Runtime/Dfa/DFA.cs @@ -248,7 +248,7 @@ public virtual bool IsEmpty { if (IsPrecedenceDfa) { - return s0.Get().EdgeMap.Count == 0 && s0full.Get().EdgeMap.Count == 0; + return s0.Get().IsEdgeMapEmpty && s0full.Get().IsEdgeMapEmpty; } return s0.Get() == null && s0full.Get() == null; } @@ -260,7 +260,7 @@ public virtual bool IsContextSensitive { if (IsPrecedenceDfa) { - return s0full.Get().EdgeMap.Count != 0; + return !s0full.Get().IsEdgeMapEmpty; } return s0full.Get() != null; } diff --git a/runtime/CSharp/Antlr4.Runtime/Dfa/DFAState.cs b/runtime/CSharp/Antlr4.Runtime/Dfa/DFAState.cs index 8d6f4f12..29abba17 100644 --- a/runtime/CSharp/Antlr4.Runtime/Dfa/DFAState.cs +++ b/runtime/CSharp/Antlr4.Runtime/Dfa/DFAState.cs @@ -207,6 +207,14 @@ public virtual ReadOnlyDictionary EdgeMap } } + public bool IsEdgeMapEmpty + { + get + { + return edges.IsEmpty; + } + } + public virtual DFAState GetContextTarget(int invokingState) { lock (this)