Skip to content

Commit f9cddc6

Browse files
committed
Tweak 'Remove' internal helper
1 parent 0cf3b25 commit f9cddc6

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/ConditionalWeakTable.cs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -185,15 +185,7 @@ public bool Remove(TKey key, [MaybeNullWhen(false)] out TValue value)
185185

186186
lock (_lock)
187187
{
188-
bool found = _container.Remove(key, out object? valueObject);
189-
190-
// We can safely suppress the nullability warning here, because if we did find the key,
191-
// the retrieved value is guaranteed to not be null. The 'Remove' method on the container
192-
// doesn't have that annotation just because it's looking for an index, not a boolean,
193-
// and there's no way to express something like '[MaybeNullWhen(!= 1)]'.
194-
value = Unsafe.As<TValue>(valueObject!);
195-
196-
return found;
188+
return _container.Remove(key, out value);
197189
}
198190
}
199191

@@ -728,17 +720,19 @@ internal void RemoveAllKeys()
728720
}
729721

730722
/// <summary>Removes the specified key from the table, if it exists.</summary>
731-
internal bool Remove(TKey key, out object? value)
723+
internal bool Remove(TKey key, [MaybeNullWhen(false)] out TValue value)
732724
{
733725
VerifyIntegrity();
734726

735-
int entryIndex = FindEntry(key, out value);
727+
int entryIndex = FindEntry(key, out object? valueObject);
736728
if (entryIndex != -1)
737729
{
738730
RemoveIndex(entryIndex);
731+
value = Unsafe.As<TValue>(valueObject);
739732
return true;
740733
}
741734

735+
value = null;
742736
return false;
743737
}
744738

0 commit comments

Comments
 (0)