Skip to content

Commit 7ea2e74

Browse files
committed
perf: use Map.computeIfAbsent in SyncRegistry
1 parent 26af7f2 commit 7ea2e74

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

  • org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/registry

org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/registry/SyncRegistry.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,21 +114,22 @@ public IGrammar grammarForScopeName(
114114
@Nullable final Map<String, Integer> embeddedLanguages,
115115
@Nullable final Map<String, Integer> tokenTypes,
116116
@Nullable final BalancedBracketSelectors balancedBracketSelectors) {
117-
if (!this._grammars.containsKey(scopeName)) {
118-
final var rawGrammar = lookup(scopeName);
117+
118+
return this._grammars.computeIfAbsent(scopeName, scopeName_ -> {
119+
final var rawGrammar = lookup(scopeName_);
119120
if (rawGrammar == null) {
120121
return null;
121122
}
122-
this._grammars.put(scopeName, new Grammar(
123-
scopeName,
123+
124+
return new Grammar(
125+
scopeName_,
124126
rawGrammar,
125127
initialLanguage,
126128
embeddedLanguages,
127129
tokenTypes,
128130
balancedBracketSelectors,
129131
this,
130-
this));
131-
}
132-
return this._grammars.get(scopeName);
132+
this);
133+
});
133134
}
134135
}

0 commit comments

Comments
 (0)