Re:How many keywords I can fit into a single C# expression?
by munchbunny on Thursday February 07, 2019 @02:59PM
(#19107995)
I'm curious what you saw. My understanding was that it's mostly generators, i.e. it's done through yields, not extra allocated arrays.
[ Parent
| on HN ]
Re:How many keywords I can fit into a single C# expression?
by 0xffff2 on Thursday February 07, 2019 @03:22PM
(#19108196)
It's `ToArray` itself that's the problem. Since it doesn't know how big the array will be in the first place, it has to allocate a small array, start iterating, copy everything into a bigger array each time it runs out of space, and finally allocate an array of exactly the right size and copy everything into that.
You can see the `ToArray` implementation at [0], which defers the implementation to [1]. The implementation checks for ICollection to get the exact size, but the type [2] that `Select` returns doesn't implement ICollection, so `ToArray` has to fall back to the less efficient algorithm.
[0] https://referencesource.microsoft.com/#System.Core/System/Li...
[1] https://referencesource.microsoft.com/#System.Core/System/Li...
[2] https://referencesource.microsoft.com/#System.Core/System/Li...
Re:How many keywords I can fit into a single C# expression?
by cm2187 on Thursday February 07, 2019 @04:55PM
(#19108966)
That's more or less what I had in mind without being certain of the details.
Was trying to open your links but I am served an expired tls certificate from Microsoft!
Re:How many keywords I can fit into a single C# expression?
by 0xffff2 on Thursday February 07, 2019 @06:56PM
(#19109907)
Oddly enough it seems that the certificate just happened to expire today in between the posting of my first and second comment. I didn't mention it only because I'm at work and couldn't be 100% certain that it's not my organizations security service messing with things.