Replies: 1 comment
-
Because calling LINQ through the |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The summary for the class
ImmuableArrayExtensions
says "LINQ extension method overrides that offer greater efficiency for ImmutableArray<T> than the standard LINQ methods". Having looked through the class and compared the method implementations to the respective LINQ methods I believe I can understand how it is done. There seem to be inconsistencies between theImmutableArrayExtension
methods, however, and I am curious why; is it because different programmers added different methods and did not follow existing patterns, or is it because the pattern was improved with time, or is it because of some performance reason?Guard Clauses:
Only 11/29 methods use the
immutableArray.ThrowNullRefIfNotInitialized()
guard clause.Even stranger is the fact that there are "related methods" where one method has the guard clause and the other does not, such as
public static T Single<T>(this ImmutableArray<T> immutableArray)
that has it andpublic static T Single<T>(this ImmutableArray<T> immutableArray, Func<T, bool> predicate)
that does not.Custom Implementations vs LINQ Calls:
There are some methods that, as far I can tell, have no custom implementation but simply calls the LINQ extension method. Compare the following two methods:
I would have expected the latter to written as
Am I wrong in thinking that the
public static T? LastOrDefault<T>(this ImmutableArray<T> immutableArray)
provides no benefit over the matching LINQ method? Perhaps even worse performance due to the additional method call?I am in the process of copying the
ImmutableArray
type but changing the implementation to use value semantics. The "inconsistencies" above made me curious if there is some voodoo going on and I should leave the methods as is, or if I should update them in my implementation.Beta Was this translation helpful? Give feedback.
All reactions