-
Notifications
You must be signed in to change notification settings - Fork 213
Assume all List implementations have an EfficientLength #223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This is a good point to bring up, but doesn't totally nullify #208. Even if But overall, yes, I think language features that desugar to calling methods on Lists should be able to assume |
Sure. I think at that point you let the compiler decide - if it can tell its backed by a |
All lists are assumed to have efficient length because the The issue in #208 is not whether Those are the tradeoffs, between predictability of behavior, understandability by users, and performance. We don't want a to just leave the door open to arbitrary use of the available API of the object (no If you create your own simple wrapper around something, in order to make it spreadable, which functions must you implement. Say: /// The sequence of individual one-codepoint strings of a string.
/// Only used for spreading: `var chars = [ ... _Chars("string"), "a"]`
class _Chars extends Iterable<String> /* or List<String> ?*/{
final String _string;
noSuchMethod(i) => throw Unimplemented(i.memberName);
... implement what here? ...
Iterator<String> get iterator => _string.runes.map((i) => String.fromCharCode(i)).iterator;
int get length => _string.runes.length;
} If we say that we always and only use The original choice was "always use iterator". That's what So, #208 is almost entirely independent of Also |
Today, a small number of SDK-only collections may implement
EfficientLengthIterable
:dart-lang/sdk#29862
In #208, @leafpetersen states:
I have another suggestion, just change this assumption:
List
implementations are now assumed to have an efficient length.EfficientLengthIterable
from the internal SDK.implements List<T>
fromLinkedList
if necessary.As a benefit, this would:
List
use the Iterable protocol or direct iteration? #208.for (var i =, l =
loops over hot code everywhere.... this doesn't solve classes that don't implement
List
(likeBuiltList
), but they aren't worse, either.The text was updated successfully, but these errors were encountered: