Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 846ed76

Browse files
committedFeb 10, 2018
TransportConnection IFeatureCollection
1 parent 399df2f commit 846ed76

File tree

3 files changed

+81
-49
lines changed

3 files changed

+81
-49
lines changed
 

‎src/Kestrel.Core/Internal/Http/HttpProtocol.Generated.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ void IFeatureCollection.Set<TFeature>(TFeature feature)
368368

369369
TFeature IFeatureCollection.Get<TFeature>()
370370
{
371-
TFeature feature;
371+
TFeature feature = default;
372372
if (typeof(TFeature) == typeof(IHttpRequestFeature))
373373
{
374374
feature = (TFeature)_currentIHttpRequestFeature;
@@ -453,17 +453,17 @@ TFeature IFeatureCollection.Get<TFeature>()
453453
{
454454
feature = (TFeature)_currentIHttpSendFileFeature;
455455
}
456-
else
456+
else if (MaybeExtra != null)
457457
{
458458
feature = (TFeature)(ExtraFeatureGet(typeof(TFeature)));
459459
}
460-
461-
if (feature != null)
460+
461+
if (feature == null)
462462
{
463-
return feature;
463+
feature = ConnectionFeatures.Get<TFeature>();
464464
}
465465

466-
return (TFeature)ConnectionFeatures[typeof(TFeature)];
466+
return feature;
467467
}
468468

469469
private IEnumerable<KeyValuePair<Type, object>> FastEnumerable()

‎src/Kestrel.Transport.Abstractions/Internal/TransportConnection.Features.cs

+69-37
Original file line numberDiff line numberDiff line change
@@ -112,69 +112,101 @@ IDuplexPipe IConnectionTransportFeature.Application
112112

113113
object IFeatureCollection.this[Type key]
114114
{
115-
get => FastFeatureGet(key);
116-
set => FastFeatureSet(key, value);
117-
}
115+
get
116+
{
117+
if (key == IHttpConnectionFeatureType)
118+
{
119+
return _currentIHttpConnectionFeature;
120+
}
118121

119-
TFeature IFeatureCollection.Get<TFeature>()
120-
{
121-
return (TFeature)FastFeatureGet(typeof(TFeature));
122-
}
122+
if (key == IConnectionIdFeatureType)
123+
{
124+
return _currentIConnectionIdFeature;
125+
}
123126

124-
void IFeatureCollection.Set<TFeature>(TFeature instance)
125-
{
126-
FastFeatureSet(typeof(TFeature), instance);
127-
}
127+
if (key == IConnectionTransportFeatureType)
128+
{
129+
return _currentIConnectionTransportFeature;
130+
}
128131

129-
IEnumerator<KeyValuePair<Type, object>> IEnumerable<KeyValuePair<Type, object>>.GetEnumerator() => FastEnumerable().GetEnumerator();
132+
if (MaybeExtra != null)
133+
{
134+
return ExtraFeatureGet(key);
135+
}
130136

131-
IEnumerator IEnumerable.GetEnumerator() => FastEnumerable().GetEnumerator();
137+
return null;
138+
}
139+
set
140+
{
141+
_featureRevision++;
132142

133-
private object FastFeatureGet(Type key)
143+
if (key == IHttpConnectionFeatureType)
144+
{
145+
_currentIHttpConnectionFeature = value;
146+
}
147+
else if (key == IConnectionIdFeatureType)
148+
{
149+
_currentIConnectionIdFeature = value;
150+
}
151+
else if (key == IConnectionTransportFeatureType)
152+
{
153+
_currentIConnectionTransportFeature = value;
154+
}
155+
else
156+
{
157+
ExtraFeatureSet(key, value);
158+
}
159+
}
160+
}
161+
162+
TFeature IFeatureCollection.Get<TFeature>()
134163
{
135-
if (key == IHttpConnectionFeatureType)
164+
if (typeof(TFeature) == typeof(IHttpConnectionFeature))
136165
{
137-
return _currentIHttpConnectionFeature;
166+
return (TFeature)_currentIHttpConnectionFeature;
138167
}
139-
140-
if (key == IConnectionIdFeatureType)
168+
else if (typeof(TFeature) == typeof(IConnectionIdFeature))
141169
{
142-
return _currentIConnectionIdFeature;
170+
return (TFeature)_currentIConnectionIdFeature;
143171
}
144-
145-
if (key == IConnectionTransportFeatureType)
172+
else if (typeof(TFeature) == typeof(IConnectionTransportFeature))
146173
{
147-
return _currentIConnectionTransportFeature;
174+
return (TFeature)_currentIConnectionTransportFeature;
175+
}
176+
else if (MaybeExtra != null)
177+
{
178+
return (TFeature)ExtraFeatureGet(typeof(TFeature));
148179
}
149180

150-
return ExtraFeatureGet(key);
181+
return default;
151182
}
152183

153-
private void FastFeatureSet(Type key, object feature)
184+
void IFeatureCollection.Set<TFeature>(TFeature instance)
154185
{
155186
_featureRevision++;
156187

157-
if (key == IHttpConnectionFeatureType)
188+
if (typeof(TFeature) == typeof(IHttpConnectionFeature))
158189
{
159-
_currentIHttpConnectionFeature = feature;
160-
return;
190+
_currentIHttpConnectionFeature = instance;
161191
}
162-
163-
if (key == IConnectionIdFeatureType)
192+
else if (typeof(TFeature) == typeof(IConnectionIdFeature))
164193
{
165-
_currentIConnectionIdFeature = feature;
166-
return;
194+
_currentIConnectionIdFeature = instance;
167195
}
168-
169-
if (key == IConnectionTransportFeatureType)
196+
else if (typeof(TFeature) == typeof(IConnectionTransportFeature))
170197
{
171-
_currentIConnectionTransportFeature = feature;
172-
return;
198+
_currentIConnectionTransportFeature = instance;
199+
}
200+
else
201+
{
202+
ExtraFeatureSet(typeof(TFeature), instance);
173203
}
174-
175-
ExtraFeatureSet(key, feature);
176204
}
177205

206+
IEnumerator<KeyValuePair<Type, object>> IEnumerable<KeyValuePair<Type, object>>.GetEnumerator() => FastEnumerable().GetEnumerator();
207+
208+
IEnumerator IEnumerable.GetEnumerator() => FastEnumerable().GetEnumerator();
209+
178210
private IEnumerable<KeyValuePair<Type, object>> FastEnumerable()
179211
{
180212
if (_currentIHttpConnectionFeature != null)

‎tools/CodeGenerator/HttpProtocolFeatureCollection.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -160,22 +160,22 @@ void IFeatureCollection.Set<TFeature>(TFeature feature)
160160

161161
TFeature IFeatureCollection.Get<TFeature>()
162162
{{
163-
TFeature feature;{Each(allFeatures, feature => $@"
163+
TFeature feature = default;{Each(allFeatures, feature => $@"
164164
{(feature.Index != 0 ? "else " : "")}if (typeof(TFeature) == typeof({feature.Name}))
165165
{{
166166
feature = (TFeature)_current{feature.Name};
167167
}}")}
168-
else
168+
else if (MaybeExtra != null)
169169
{{
170170
feature = (TFeature)(ExtraFeatureGet(typeof(TFeature)));
171171
}}
172-
173-
if (feature != null)
172+
173+
if (feature == null)
174174
{{
175-
return feature;
175+
feature = ConnectionFeatures.Get<TFeature>();
176176
}}
177177

178-
return (TFeature)ConnectionFeatures[typeof(TFeature)];
178+
return feature;
179179
}}
180180

181181
private IEnumerable<KeyValuePair<Type, object>> FastEnumerable()

0 commit comments

Comments
 (0)
This repository has been archived.