Skip to content
Open
Changes from 1 commit
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
9 changes: 4 additions & 5 deletions src/Shared/Dictionary/AdaptiveCapacityDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Microsoft.AspNetCore.Shared;

namespace Microsoft.AspNetCore.Internal;
Expand Down Expand Up @@ -545,8 +544,7 @@ private Span<KeyValuePair<TKey, TValue>> ArrayStorageSpan
Debug.Assert(_arrayStorage is not null);
Debug.Assert(_count <= _arrayStorage.Length);

ref var r = ref MemoryMarshal.GetArrayDataReference(_arrayStorage);
return MemoryMarshal.CreateSpan(ref r, _count);
return _arrayStorage.AsSpan(0, _count);
}
}

Expand All @@ -558,9 +556,10 @@ private int FindIndex(TKey key)

if (_count > 0)
{
for (var i = 0; i < ArrayStorageSpan.Length; ++i)
var arrayStorageSpanLocal = ArrayStorageSpan; // call Span.Slice once rather than within loop
for (var i = 0; i < arrayStorageSpanLocal.Length; ++i)
{
if (_comparer.Equals(ArrayStorageSpan[i].Key, key))
if (_comparer.Equals(arrayStorageSpanLocal[i].Key, key))
{
return i;
}
Expand Down
Loading