diff --git a/src/TextMateSharp/Internal/Grammars/BasicScopeAttributesProvider.cs b/src/TextMateSharp/Internal/Grammars/BasicScopeAttributesProvider.cs index e3abe5f..e6bed5b 100644 --- a/src/TextMateSharp/Internal/Grammars/BasicScopeAttributesProvider.cs +++ b/src/TextMateSharp/Internal/Grammars/BasicScopeAttributesProvider.cs @@ -123,7 +123,7 @@ private int ScopeToLanguage(string scope) } string scopeName = m.Groups[1].Value; - return _embeddedLanguages.ContainsKey(scopeName) ? _embeddedLanguages[scopeName] : 0; + return _embeddedLanguages.TryGetValue(scopeName, out int value) ? value : 0; } private static int ToStandardTokenType(string tokenType) diff --git a/src/TextMateSharp/Internal/Grammars/Grammar.cs b/src/TextMateSharp/Internal/Grammars/Grammar.cs index 4ea40da..8700f84 100644 --- a/src/TextMateSharp/Internal/Grammars/Grammar.cs +++ b/src/TextMateSharp/Internal/Grammars/Grammar.cs @@ -156,9 +156,9 @@ public IRawGrammar GetExternalGrammar(string scopeName) public IRawGrammar GetExternalGrammar(string scopeName, IRawRepository repository) { - if (this._includedGrammars.ContainsKey(scopeName)) + if (_includedGrammars.TryGetValue(scopeName, out IRawGrammar value)) { - return this._includedGrammars[scopeName]; + return value; } else if (this._grammarRepository != null) { diff --git a/src/TextMateSharp/Internal/Grammars/SyncRegistry.cs b/src/TextMateSharp/Internal/Grammars/SyncRegistry.cs index 7f0fdce..5702f67 100644 --- a/src/TextMateSharp/Internal/Grammars/SyncRegistry.cs +++ b/src/TextMateSharp/Internal/Grammars/SyncRegistry.cs @@ -91,15 +91,15 @@ public IGrammar GrammarForScopeName( Dictionary tokenTypes, BalancedBracketSelectors balancedBracketSelectors) { - if (!this._grammars.ContainsKey(scopeName)) + if (!_grammars.TryGetValue(scopeName, out IGrammar value)) { IRawGrammar rawGrammar = Lookup(scopeName); if (rawGrammar == null) { return null; } - this._grammars.Add(scopeName, - new Grammar( + + value = new Grammar( scopeName, rawGrammar, initialLanguage, @@ -107,9 +107,10 @@ public IGrammar GrammarForScopeName( tokenTypes, balancedBracketSelectors, this, - this)); + this); + this._grammars.Add(scopeName, value); } - return this._grammars[scopeName]; + return value; } private static void CollectIncludedScopes(ICollection result, IRawGrammar grammar) diff --git a/src/TextMateSharp/Themes/Theme.cs b/src/TextMateSharp/Themes/Theme.cs index 395f939..e179c31 100644 --- a/src/TextMateSharp/Themes/Theme.cs +++ b/src/TextMateSharp/Themes/Theme.cs @@ -322,11 +322,12 @@ internal List Match(string scopeName) { lock (this._cachedMatchRoot) { - if (!this._cachedMatchRoot.ContainsKey(scopeName)) + if (!_cachedMatchRoot.TryGetValue(scopeName, out List value)) { - this._cachedMatchRoot[scopeName] = this._root.Match(scopeName); + value = this._root.Match(scopeName); + this._cachedMatchRoot[scopeName] = value; } - return this._cachedMatchRoot[scopeName]; + return value; } } diff --git a/src/TextMateSharp/Themes/ThemeTrieElement.cs b/src/TextMateSharp/Themes/ThemeTrieElement.cs index 94e67db..9def467 100644 --- a/src/TextMateSharp/Themes/ThemeTrieElement.cs +++ b/src/TextMateSharp/Themes/ThemeTrieElement.cs @@ -94,9 +94,9 @@ public List Match(string scope) tail = scope.Substring(dotIndex + 1); } - if (this.children.ContainsKey(head)) + if (children.TryGetValue(head, out ThemeTrieElement value)) { - return this.children[head].Match(tail); + return value.Match(tail); } arr = new List(); @@ -130,9 +130,9 @@ public void Insert(string name, int scopeDepth, string scope, List paren } ThemeTrieElement child; - if (this.children.ContainsKey(head)) + if (children.TryGetValue(head, out ThemeTrieElement value)) { - child = this.children[head]; + child = value; } else {