Merge branch 'merge/release/2.2-to-master'

This commit is contained in:
James Newton-King 2018-08-22 10:48:44 +12:00
commit 8b0a598a64
No known key found for this signature in database
GPG Key ID: 0A66B2F456BF5526
6 changed files with 44 additions and 38 deletions

View File

@ -112,8 +112,7 @@ namespace Microsoft.AspNetCore.Routing
var items = new List<T>(); var items = new List<T>();
for (var i = 0; i < _items.Length; i++) for (var i = 0; i < _items.Length; i++)
{ {
var item = _items[i] as T; if (_items[i] is T item)
if (item != null)
{ {
items.Add(item); items.Add(item);
} }
@ -150,19 +149,18 @@ namespace Microsoft.AspNetCore.Routing
// Intentionally not readonly to prevent defensive struct copies // Intentionally not readonly to prevent defensive struct copies
private object[] _items; private object[] _items;
private int _index; private int _index;
private object _current;
internal Enumerator(EndpointMetadataCollection collection) internal Enumerator(EndpointMetadataCollection collection)
{ {
_items = collection._items; _items = collection._items;
_index = 0; _index = 0;
_current = null; Current = null;
} }
/// <summary> /// <summary>
/// Gets the element at the current position of the enumerator /// Gets the element at the current position of the enumerator
/// </summary> /// </summary>
public object Current => _current; public object Current { get; private set; }
/// <summary> /// <summary>
/// Releases all resources used by the <see cref="Enumerator"/>. /// Releases all resources used by the <see cref="Enumerator"/>.
@ -182,11 +180,11 @@ namespace Microsoft.AspNetCore.Routing
{ {
if (_index < _items.Length) if (_index < _items.Length)
{ {
_current = _items[_index++]; Current = _items[_index++];
return true; return true;
} }
_current = null; Current = null;
return false; return false;
} }
@ -196,7 +194,7 @@ namespace Microsoft.AspNetCore.Routing
public void Reset() public void Reset()
{ {
_index = 0; _index = 0;
_current = null; Current = null;
} }
} }
} }

View File

@ -222,13 +222,7 @@ namespace Microsoft.AspNetCore.Routing
} }
} }
IEnumerable<string> IReadOnlyDictionary<string, object>.Keys IEnumerable<string> IReadOnlyDictionary<string, object>.Keys => Keys;
{
get
{
return Keys;
}
}
/// <inheritdoc /> /// <inheritdoc />
public ICollection<object> Values public ICollection<object> Values
@ -248,13 +242,7 @@ namespace Microsoft.AspNetCore.Routing
} }
} }
IEnumerable<object> IReadOnlyDictionary<string, object>.Values IEnumerable<object> IReadOnlyDictionary<string, object>.Values => Values;
{
get
{
return Values;
}
}
/// <inheritdoc /> /// <inheritdoc />
void ICollection<KeyValuePair<string, object>>.Add(KeyValuePair<string, object> item) void ICollection<KeyValuePair<string, object>>.Add(KeyValuePair<string, object> item)
@ -565,7 +553,7 @@ namespace Microsoft.AspNetCore.Routing
internal class PropertyStorage internal class PropertyStorage
{ {
private static readonly PropertyCache _propertyCache = new PropertyCache(); private static readonly ConcurrentDictionary<Type, PropertyHelper[]> _propertyCache = new ConcurrentDictionary<Type, PropertyHelper[]>();
public readonly object Value; public readonly object Value;
public readonly PropertyHelper[] Properties; public readonly PropertyHelper[] Properties;
@ -606,9 +594,5 @@ namespace Microsoft.AspNetCore.Routing
} }
} }
} }
private class PropertyCache : ConcurrentDictionary<Type, PropertyHelper[]>
{
}
} }
} }

View File

@ -21,10 +21,10 @@ namespace Microsoft.AspNetCore.Routing.Patterns
internal RoutePattern( internal RoutePattern(
string rawText, string rawText,
Dictionary<string, object> defaults, IReadOnlyDictionary<string, object> defaults,
Dictionary<string, IReadOnlyList<RoutePatternConstraintReference>> constraints, IReadOnlyDictionary<string, IReadOnlyList<RoutePatternConstraintReference>> constraints,
RoutePatternParameterPart[] parameters, IReadOnlyList<RoutePatternParameterPart> parameters,
RoutePatternPathSegment[] pathSegments) IReadOnlyList<RoutePatternPathSegment> pathSegments)
{ {
Debug.Assert(defaults != null); Debug.Assert(defaults != null);
Debug.Assert(constraints != null); Debug.Assert(constraints != null);

View File

@ -298,19 +298,35 @@ namespace Microsoft.AspNetCore.Routing.Patterns
rawText, rawText,
updatedDefaults, updatedDefaults,
updatedConstraints.ToDictionary(kvp => kvp.Key, kvp => (IReadOnlyList<RoutePatternConstraintReference>)kvp.Value.ToArray()), updatedConstraints.ToDictionary(kvp => kvp.Key, kvp => (IReadOnlyList<RoutePatternConstraintReference>)kvp.Value.ToArray()),
parameters.ToArray(), parameters,
updatedSegments.ToArray()); updatedSegments);
RoutePatternPathSegment VisitSegment(RoutePatternPathSegment segment) RoutePatternPathSegment VisitSegment(RoutePatternPathSegment segment)
{ {
var updatedParts = new RoutePatternPart[segment.Parts.Count]; RoutePatternPart[] updatedParts = null;
for (var i = 0; i < segment.Parts.Count; i++) for (var i = 0; i < segment.Parts.Count; i++)
{ {
var part = segment.Parts[i]; var part = segment.Parts[i];
updatedParts[i] = VisitPart(part); var updatedPart = VisitPart(part);
if (part != updatedPart)
{
if (updatedParts == null)
{
updatedParts = segment.Parts.ToArray();
}
updatedParts[i] = updatedPart;
}
} }
return SegmentCore(updatedParts); if (updatedParts == null)
{
// Segment has not changed
return segment;
}
return new RoutePatternPathSegment(updatedParts);
} }
RoutePatternPart VisitPart(RoutePatternPart part) RoutePatternPart VisitPart(RoutePatternPart part)
@ -357,6 +373,14 @@ namespace Microsoft.AspNetCore.Routing.Patterns
parameterConstraints.AddRange(parameter.Constraints); parameterConstraints.AddRange(parameter.Constraints);
} }
if (Equals(parameter.Default, @default)
&& parameter.Constraints.Count == 0
&& (parameterConstraints?.Count ?? 0) == 0)
{
// Part has not changed
return part;
}
return ParameterPartCore( return ParameterPartCore(
parameter.Name, parameter.Name,
@default, @default,

View File

@ -138,7 +138,7 @@ namespace Microsoft.AspNetCore.Routing.Patterns
if (IsSegmentValid(context, parts)) if (IsSegmentValid(context, parts))
{ {
segments.Add(new RoutePatternPathSegment(parts.ToArray())); segments.Add(new RoutePatternPathSegment(parts));
return true; return true;
} }
else else

View File

@ -20,7 +20,7 @@ namespace Microsoft.AspNetCore.Routing.Patterns
[DebuggerDisplay("{DebuggerToString()}")] [DebuggerDisplay("{DebuggerToString()}")]
public sealed class RoutePatternPathSegment public sealed class RoutePatternPathSegment
{ {
internal RoutePatternPathSegment(RoutePatternPart[] parts) internal RoutePatternPathSegment(IReadOnlyList<RoutePatternPart> parts)
{ {
Parts = parts; Parts = parts;
} }