fsharp/fsharp — pull request #217 by jack-pappas (2013-12-27 18:06:47+00:00)
Title: Optimized the implementation of the 'dict' operator

I've optimized the implementation of the ``dict`` operator so it checks the type of the input sequence and uses an optimized codepath (if possible) when building the underlying mutable dictionary. These optimized codepaths are able to iterate over the input data more efficiently; importantly, for some input data types (e.g., an array) where it is fast and easy to determine the count/length of the sequence, it allows the underlying dictionary to be initialized to the exact capacity needed -- which avoids unnecessarily resizing the dictionary while adding the data.

Additionally, I've modified the implementation of the ``IDictionary<_,_>.TryGetValue()`` method in the object expression which creates the immutable dictionary implementation. The original version calls ``.ContainsKey()`` then separately retrieves the value if found; now, it uses ``.TryGetValue()`` on the underlying mutable dictionary to accomplish the same thing with just one lookup.