Map putIfAbsent to GetOrAdd

This commit is contained in:
Sam Harwell 2014-07-04 20:38:40 -05:00
parent 9a23a7f3c5
commit 8a062443af
3 changed files with 5 additions and 3 deletions

View File

@ -23,6 +23,8 @@
-methodMapping java.util.AbstractList.addAll AddRange -methodMapping java.util.AbstractList.addAll AddRange
-methodMapping java.util.ArrayList.addAll AddRange -methodMapping java.util.ArrayList.addAll AddRange
-methodMapping java.util.concurrent.ConcurrentMap.putIfAbsent GetOrAdd
-fullyQualify File -fullyQualify File
-namespaceMapping java.lang.ref Antlr4.Runtime.Sharpen -namespaceMapping java.lang.ref Antlr4.Runtime.Sharpen
-namespaceMapping java.lang Antlr4.Runtime.Sharpen -namespaceMapping java.lang Antlr4.Runtime.Sharpen

View File

@ -353,7 +353,7 @@ namespace Antlr4.Runtime.Atn
} }
if (!changed) if (!changed)
{ {
existing = contextCache.PutIfAbsent(context, context); existing = contextCache.GetOrAdd(context, context);
visited.Put(context, existing != null ? existing : context); visited.Put(context, existing != null ? existing : context);
return context; return context;
} }
@ -368,7 +368,7 @@ namespace Antlr4.Runtime.Atn
ArrayPredictionContext arrayPredictionContext = (ArrayPredictionContext)context; ArrayPredictionContext arrayPredictionContext = (ArrayPredictionContext)context;
updated = new ArrayPredictionContext(parents, arrayPredictionContext.returnStates, context.cachedHashCode); 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(updated, existing != null ? existing : updated);
visited.Put(context, existing != null ? existing : updated); visited.Put(context, existing != null ? existing : updated);
return updated; return updated;

View File

@ -267,7 +267,7 @@ namespace Antlr4.Runtime.Dfa
public virtual DFAState AddState(DFAState state) public virtual DFAState AddState(DFAState state)
{ {
state.stateNumber = nextStateNumber.GetAndIncrement(); state.stateNumber = nextStateNumber.GetAndIncrement();
DFAState existing = states.PutIfAbsent(state, state); DFAState existing = states.GetOrAdd(state, state);
if (existing != null) if (existing != null)
{ {
return existing; return existing;