Reduce allocations when RouteValueDictionary is initialized from another empty (array-based) RouteValueDictionary.
When RouteValueDictionary is initialized from another non-empty array-based RouteValueDictionary, then only allocate an array that corresponds with the number of items in that RouteValueDictionary instead of the capacity.
Refactor ContainsKey(string key) to use newly introduced ContainsKeyArray(string key) and ContainsKeyProperties(string key) methods that do not obtain the value of the key. This mostly affects the path where we're using property storage.
Update Add(string key, object value) and TryAdd(string key, object value) to use ContainsKeyArray(string key) to check whether an entry with the specified key already exists.
Improve performance of TryAdd(string key, object value) when backed by properties, and eliminate extra array allocation when number of properties is equal to capacity.
ContainsKey(string key)
to use newly introducedContainsKeyArray(string key)
andContainsKeyProperties(string key)
methods that do not obtain the value of the key. This mostly affects the path where we're using property storage.Add(string key, object value)
andTryAdd(string key, object value)
to useContainsKeyArray(string key)
to check whether an entry with the specified key already exists.TryAdd(string key, object value)
when backed by properties, and eliminate extra array allocation when number of properties is equal to capacity.Benchmarks: