You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm aware this optimization may be considered "too niche", but I believe it makes more sense for a compiler to do this automatically than for a human to explicitly use this algorithm at runtime.
I'm also aware of the fact that it would be unlikely for an optimizer to infer that a dynamically-generated list has all of its values sorted and that the set of unique values is small relative to the list length.
However, it's much easier to apply this optimization if the list contents are statically-known. Yes, the optimizer might prefer to do constant-folding, but if the list is big enough it might be better to fold at runtime, where this optimization shines