Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary calls to Contains for sets #69179

Merged
merged 3 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -592,8 +592,7 @@ public void ISet_Generic_SymmetricExceptWith_AfterRemovingElements(EnumerableTyp
{
ISet<T> set = GenericISetFactory(setLength);
T value = CreateT(532);
if (!set.Contains(value))
set.Add(value);
set.Add(value);
set.Remove(value);
IEnumerable<T> enumerable = CreateEnumerable(enumerableType, set, enumerableLength, numberOfMatchingElements, numberOfDuplicateElements);
Debug.Assert(enumerable != null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2070,10 +2070,8 @@ private MethodSymbol FindMethodSymbolInSuperType(TypeDefinitionHandle searchType
TypeDefinitionHandle typeDef = typeDefsToSearch.Dequeue();
Debug.Assert(!typeDef.IsNil);

if (!visitedTypeDefTokens.Contains(typeDef))
if (visitedTypeDefTokens.Add(typeDef))
{
visitedTypeDefTokens.Add(typeDef);

foreach (MethodDefinitionHandle methodDef in Module.GetMethodsOfTypeOrThrow(typeDef))
{
if (methodDef == targetMethodDef)
Expand All @@ -2091,12 +2089,9 @@ private MethodSymbol FindMethodSymbolInSuperType(TypeDefinitionHandle searchType
TypeSymbol typeSymbol = typeSymbolsToSearch.Dequeue();
Debug.Assert(typeSymbol != null);

if (!visitedTypeSymbols.Contains(typeSymbol))
if (visitedTypeSymbols.Add(typeSymbol))
{
visitedTypeSymbols.Add(typeSymbol);

//we're looking for a method def but we're currently on a type *ref*, so just enqueue supertypes

EnqueueTypeSymbolInterfacesAndBaseTypes(typeDefsToSearch, typeSymbolsToSearch, typeSymbol);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1802,9 +1802,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
Dim candidateLocation As Location = candidate.NonMergedLocation
Debug.Assert(candidateLocation IsNot Nothing)

If partialMethods.Contains(candidate) Then
If partialMethods.Remove(candidate) Then
' partial-partial conflict
partialMethods.Remove(candidate)

' the 'best' partial method is the one with the 'smallest'
' location, we should report errors on the other
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,8 @@ void ITextViewConnectionListener.SubjectBuffersDisconnected(ITextView textView,
if (reason == ConnectionReason.TextViewLifetime ||
!textView.BufferGraph.GetTextBuffers(b => b.ContentType.IsOfType(ContentTypeNames.RoslynContentType)).Any())
{
if (_subscribedViews.Contains(textView))
if (_subscribedViews.Remove(textView))
{
_subscribedViews.Remove(textView);
textView.Caret.PositionChanged -= OnTextViewCaretPositionChanged;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,7 @@ internal void Remove()
{
var parameterToRemove = AllParameters[_selectedIndex!.Value];

if (_parametersWithoutDefaultValues.Contains(parameterToRemove))
{
_parametersWithoutDefaultValues.Remove(parameterToRemove);
}
else
if (!_parametersWithoutDefaultValues.Remove(parameterToRemove))
{
_parametersWithDefaultValues.Remove(parameterToRemove);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,7 @@ public TValue Remove(TKey key)
{
this.AssertIsForeground();

if (_deadKeySet.Contains(key))
{
_deadKeySet.Remove(key);
}
_deadKeySet.Remove(key);

if (_table.TryGetValue(key, out var handle))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.ProjectSystemShim
' To keep things simple, we'll just remove everything and add everything back in
For Each oldRuntimeLibrary In oldRuntimeLibraries
' If this one was added explicitly in addition to our computation, we don't have to remove it
If _explicitlyAddedRuntimeLibraries.Contains(oldRuntimeLibrary) Then
_explicitlyAddedRuntimeLibraries.Remove(oldRuntimeLibrary)
Else
If Not _explicitlyAddedRuntimeLibraries.Remove(oldRuntimeLibrary) Then
ProjectSystemProject.RemoveMetadataReference(oldRuntimeLibrary, MetadataReferenceProperties.Assembly)
End If
Next
Expand Down