From 8a062443afbe9529468ef11407d5125f22edb970 Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Fri, 4 Jul 2014 20:38:40 -0500 Subject: [PATCH] Map putIfAbsent to GetOrAdd --- reference/sharpen-all-options.txt | 2 ++ runtime/CSharp/Antlr4.Runtime/Atn/PredictionContext.cs | 4 ++-- runtime/CSharp/Antlr4.Runtime/Dfa/DFA.cs | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/reference/sharpen-all-options.txt b/reference/sharpen-all-options.txt index 790305ee9..8d4da7dab 100644 --- a/reference/sharpen-all-options.txt +++ b/reference/sharpen-all-options.txt @@ -23,6 +23,8 @@ -methodMapping java.util.AbstractList.addAll AddRange -methodMapping java.util.ArrayList.addAll AddRange +-methodMapping java.util.concurrent.ConcurrentMap.putIfAbsent GetOrAdd + -fullyQualify File -namespaceMapping java.lang.ref Antlr4.Runtime.Sharpen -namespaceMapping java.lang Antlr4.Runtime.Sharpen diff --git a/runtime/CSharp/Antlr4.Runtime/Atn/PredictionContext.cs b/runtime/CSharp/Antlr4.Runtime/Atn/PredictionContext.cs index 0c13e2c81..5e750e56c 100644 --- a/runtime/CSharp/Antlr4.Runtime/Atn/PredictionContext.cs +++ b/runtime/CSharp/Antlr4.Runtime/Atn/PredictionContext.cs @@ -353,7 +353,7 @@ namespace Antlr4.Runtime.Atn } if (!changed) { - existing = contextCache.PutIfAbsent(context, context); + existing = contextCache.GetOrAdd(context, context); visited.Put(context, existing != null ? existing : context); return context; } @@ -368,7 +368,7 @@ namespace Antlr4.Runtime.Atn ArrayPredictionContext arrayPredictionContext = (ArrayPredictionContext)context; updated = new ArrayPredictionContext(parents, arrayPredictionContext.returnStates, context.cachedHashCode); } - existing = contextCache.PutIfAbsent(updated, updated); + existing = contextCache.GetOrAdd(updated, updated); visited.Put(updated, existing != null ? existing : updated); visited.Put(context, existing != null ? existing : updated); return updated; diff --git a/runtime/CSharp/Antlr4.Runtime/Dfa/DFA.cs b/runtime/CSharp/Antlr4.Runtime/Dfa/DFA.cs index 3fc6a7de5..6a02a0919 100644 --- a/runtime/CSharp/Antlr4.Runtime/Dfa/DFA.cs +++ b/runtime/CSharp/Antlr4.Runtime/Dfa/DFA.cs @@ -267,7 +267,7 @@ namespace Antlr4.Runtime.Dfa public virtual DFAState AddState(DFAState state) { state.stateNumber = nextStateNumber.GetAndIncrement(); - DFAState existing = states.PutIfAbsent(state, state); + DFAState existing = states.GetOrAdd(state, state); if (existing != null) { return existing;