Skip to content

Commit 958e7a6

Browse files
committed
Fixing requestcookiecollection
1 parent c92b557 commit 958e7a6

File tree

2 files changed

+14
-21
lines changed

2 files changed

+14
-21
lines changed

src/Http/Http/src/Internal/RequestCookieCollection.cs

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,6 @@ public string? this[string key]
4646
throw new ArgumentNullException(nameof(key));
4747
}
4848

49-
if (Store == null)
50-
{
51-
return null;
52-
}
53-
5449
if (TryGetValue(key, out var value))
5550
{
5651
return value;
@@ -87,10 +82,6 @@ public int Count
8782
{
8883
get
8984
{
90-
if (Store == null)
91-
{
92-
return 0;
93-
}
9485
return Store.Count;
9586
}
9687
}
@@ -99,26 +90,18 @@ public ICollection<string> Keys
9990
{
10091
get
10192
{
102-
if (Store == null)
103-
{
104-
return EmptyKeys;
105-
}
10693
return Store.Keys;
10794
}
10895
}
10996

11097
public bool ContainsKey(string key)
11198
{
112-
if (Store == null)
113-
{
114-
return false;
115-
}
11699
return Store.ContainsKey(key);
117100
}
118101

119102
public bool TryGetValue(string key, [MaybeNullWhen(false)] out string? value)
120103
{
121-
if (Store == null)
104+
if (Store.Count == 0)
122105
{
123106
value = null;
124107
return false;
@@ -134,7 +117,7 @@ public bool TryGetValue(string key, [MaybeNullWhen(false)] out string? value)
134117
/// <returns>An <see cref="Enumerator" /> object that can be used to iterate through the collection.</returns>
135118
public Enumerator GetEnumerator()
136119
{
137-
if (Store == null || Store.Count == 0)
120+
if ( Store.Count == 0)
138121
{
139122
// Non-boxed Enumerator
140123
return EmptyEnumerator;
@@ -149,7 +132,7 @@ public Enumerator GetEnumerator()
149132
/// <returns>An <see cref="IEnumerator{T}" /> object that can be used to iterate through the collection.</returns>
150133
IEnumerator<KeyValuePair<string, string>> IEnumerable<KeyValuePair<string, string>>.GetEnumerator()
151134
{
152-
if (Store == null || Store.Count == 0)
135+
if (Store.Count == 0)
153136
{
154137
// Non-boxed Enumerator
155138
return EmptyIEnumeratorType;
@@ -164,7 +147,7 @@ IEnumerator<KeyValuePair<string, string>> IEnumerable<KeyValuePair<string, strin
164147
/// <returns>An <see cref="IEnumerator" /> object that can be used to iterate through the collection.</returns>
165148
IEnumerator IEnumerable.GetEnumerator()
166149
{
167-
if (Store == null || Store.Count == 0)
150+
if (Store.Count == 0)
168151
{
169152
// Non-boxed Enumerator
170153
return EmptyIEnumerator;

src/Shared/Dictionary/SmallCapacityDictionary.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Collections;
66
using System.Collections.Generic;
77
using System.Diagnostics.CodeAnalysis;
8+
using System.Linq;
89
using System.Runtime.CompilerServices;
910

1011
namespace Microsoft.AspNetCore.Internal.Dictionary
@@ -95,6 +96,15 @@ public static SmallCapacityDictionary<TKey, TValue> FromArray(KeyValuePair<TKey,
9596
};
9697
}
9798

99+
/// <summary>
100+
/// Creates a <see cref="SmallCapacityDictionary{TKey, TValue}"/>.
101+
/// </summary>
102+
/// <param name="from">Dictionary to copy from.</param>
103+
public SmallCapacityDictionary(Dictionary<TKey, TValue> from)
104+
: this(from.ToList(), from.Count, EqualityComparer<TKey>.Default)
105+
{
106+
}
107+
98108
/// <summary>
99109
/// Creates a <see cref="SmallCapacityDictionary{TKey, TValue}"/>.
100110
/// </summary>

0 commit comments

Comments
 (0)