Don used cached typeof for tests

This commit is contained in:
Ben Adams 2015-10-07 01:28:35 -04:00 committed by Louis DeJardin
parent 56893df7f9
commit 3c20053d9a
2 changed files with 35 additions and 15 deletions

View File

@ -6,7 +6,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
{ {
public partial class Frame public partial class Frame
{ {
private const long flagIHttpRequestFeature = 1; private const long flagIHttpRequestFeature = 1;
private const long flagIHttpResponseFeature = 2; private const long flagIHttpResponseFeature = 2;
private const long flagIHttpRequestIdentifierFeature = 4; private const long flagIHttpRequestIdentifierFeature = 4;
@ -24,7 +23,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
private const long flagIHttpWebSocketFeature = 16384; private const long flagIHttpWebSocketFeature = 16384;
private const long flagISessionFeature = 32768; private const long flagISessionFeature = 32768;
private static readonly Type IHttpRequestFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestFeature); private static readonly Type IHttpRequestFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestFeature);
private static readonly Type IHttpResponseFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpResponseFeature); private static readonly Type IHttpResponseFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpResponseFeature);
private static readonly Type IHttpRequestIdentifierFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestIdentifierFeature); private static readonly Type IHttpRequestIdentifierFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestIdentifierFeature);
@ -41,6 +39,15 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
private static readonly Type IHttpUpgradeFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpUpgradeFeature); private static readonly Type IHttpUpgradeFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpUpgradeFeature);
private static readonly Type IHttpWebSocketFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpWebSocketFeature); private static readonly Type IHttpWebSocketFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpWebSocketFeature);
private static readonly Type ISessionFeatureType = typeof(global::Microsoft.AspNet.Http.Features.ISessionFeature); private static readonly Type ISessionFeatureType = typeof(global::Microsoft.AspNet.Http.Features.ISessionFeature);
private static readonly Type IHttpSendFileFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpSendFileFeature);
private object _currentIHttpRequestIdentifierFeature;
private object _currentIServiceProvidersFeature;
private object _currentIHttpRequestLifetimeFeature;
private object _currentIHttpConnectionFeature;
private object _currentIHttpAuthenticationFeature;
private object _currentIQueryFeature;
private object _currentIFormFeature;
private long _featureOverridenFlags = 0L; private long _featureOverridenFlags = 0L;
@ -51,7 +58,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
private object FastFeatureGet(Type key) private object FastFeatureGet(Type key)
{ {
if (key == IHttpRequestFeatureType) if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestFeature))
{ {
if ((_featureOverridenFlags & flagIHttpRequestFeature) == 0L) if ((_featureOverridenFlags & flagIHttpRequestFeature) == 0L)
{ {
@ -59,7 +66,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
} }
return SlowFeatureGet(key); return SlowFeatureGet(key);
} }
if (key == IHttpResponseFeatureType) if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpResponseFeature))
{ {
if ((_featureOverridenFlags & flagIHttpResponseFeature) == 0L) if ((_featureOverridenFlags & flagIHttpResponseFeature) == 0L)
{ {
@ -83,7 +90,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
} }
return SlowFeatureGet(key); return SlowFeatureGet(key);
} }
if (key == IServiceProvidersFeatureType) if (key == typeof(global::Microsoft.AspNet.Http.Features.Internal.IServiceProvidersFeature))
{ {
if ((_featureOverridenFlags & flagIServiceProvidersFeature) == 0L) if ((_featureOverridenFlags & flagIServiceProvidersFeature) == 0L)
{ {
@ -99,7 +106,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
} }
return SlowFeatureGet(key); return SlowFeatureGet(key);
} }
if (key == IHttpRequestLifetimeFeatureType) if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestLifetimeFeature))
{ {
if ((_featureOverridenFlags & flagIHttpRequestLifetimeFeature) == 0L) if ((_featureOverridenFlags & flagIHttpRequestLifetimeFeature) == 0L)
{ {
@ -139,7 +146,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
} }
return SlowFeatureGet(key); return SlowFeatureGet(key);
} }
if (key == IHttpConnectionFeatureType) if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpConnectionFeature))
{ {
if ((_featureOverridenFlags & flagIHttpConnectionFeature) == 0L) if ((_featureOverridenFlags & flagIHttpConnectionFeature) == 0L)
{ {
@ -218,7 +225,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
FastFeatureSetInner(flagIHttpRequestFeature, key, feature); FastFeatureSetInner(flagIHttpRequestFeature, key, feature);
return; return;
} }
if (key == IHttpResponseFeatureType) if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpResponseFeature))
{ {
FastFeatureSetInner(flagIHttpResponseFeature, key, feature); FastFeatureSetInner(flagIHttpResponseFeature, key, feature);
return; return;
@ -233,7 +240,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
FastFeatureSetInner(flagIHttpSendFileFeature, key, feature); FastFeatureSetInner(flagIHttpSendFileFeature, key, feature);
return; return;
} }
if (key == IServiceProvidersFeatureType) if (key == typeof(global::Microsoft.AspNet.Http.Features.Internal.IServiceProvidersFeature))
{ {
FastFeatureSetInner(flagIServiceProvidersFeature, key, feature); FastFeatureSetInner(flagIServiceProvidersFeature, key, feature);
return; return;
@ -243,7 +250,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
FastFeatureSetInner(flagIHttpAuthenticationFeature, key, feature); FastFeatureSetInner(flagIHttpAuthenticationFeature, key, feature);
return; return;
} }
if (key == IHttpRequestLifetimeFeatureType) if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpRequestLifetimeFeature))
{ {
FastFeatureSetInner(flagIHttpRequestLifetimeFeature, key, feature); FastFeatureSetInner(flagIHttpRequestLifetimeFeature, key, feature);
return; return;
@ -268,7 +275,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
FastFeatureSetInner(flagIItemsFeature, key, feature); FastFeatureSetInner(flagIItemsFeature, key, feature);
return; return;
} }
if (key == IHttpConnectionFeatureType) if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpConnectionFeature))
{ {
FastFeatureSetInner(flagIHttpConnectionFeature, key, feature); FastFeatureSetInner(flagIHttpConnectionFeature, key, feature);
return; return;

View File

@ -85,6 +85,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
}} }}
return SlowFeatureGet(key); return SlowFeatureGet(key);
}}")} }}")}
{Each(cachedFeatures, feature => $@"
if (key == typeof(global::{feature.FullName}))
{{
return _current{feature.Name};
}}")}
return SlowFeatureGet(key); return SlowFeatureGet(key);
}} }}
@ -118,13 +123,21 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
}} }}
private void FastFeatureSet(Type key, object feature) private void FastFeatureSet(Type key, object feature)
{{{Each(commonFeatures, feature => $@" {{
if (key == {feature.Name}Type) _featureRevision++;
{Each(implementedFeatures, feature => $@"
if (key == typeof(global::{feature.FullName}))
{{ {{
FastFeatureSetInner(flag{feature.Name}, key, feature); FastFeatureSetInner(flag{feature.Name}, key, feature);
return; return;
}}")} }}")};
Extra[key] = feature; {Each(cachedFeatures, feature => $@"
if (key == typeof(global::{feature.FullName}))
{{
_current{feature.Name} = feature;
return;
}}")};
SetExtra(key, feature);
}} }}
private IEnumerable<KeyValuePair<Type, object>> FastEnumerable() private IEnumerable<KeyValuePair<Type, object>> FastEnumerable()