Closed
Description
The method takes an IEnumerable<string>
. Things we could improve:
- Special-case
IList<string>
or some other type to avoid boxing the enumerator - Avoid double entry lookups in case of more than one value
- Avoid unnecessary
List
resizes if we already know the final size
For example
TryAddWithoutValidation("foo", "1");
TryAddWithoutValidation("foo", new[] { "2", "3" });
Will currently allocate the enumerator, a List<string>
of size 2, and a List<string>
of size 4.
We can reduce that down to allocating a single List<string>
of size 3.
An example of how this can be achieved:
https://gist.github.com/MihaZupan/800df7a324a66a8e814c3ec91f3d39b0