Skip to content
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

making all collections const #282

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

ahmednfwela
Copy link

@ahmednfwela ahmednfwela commented Jun 19, 2023

fixes #164

This PR adds a const factory BuiltList.fromList([List<E> list]) which creates a new subclass _ConstBuiltList that only has a const constructor.

a similar approach is also used to add support for const BuiltSet and other built collections.

this is a non-breaking change, since classes most likely extend BuiltList, and even if they implement it, they will just get a warning override_on_non_overriding_member lint.

However, this is however a behavioral change for people extending BuiltList themselves, since the hashCode operation is now slower, which means they will have to add back this piece of code themselves.

  int? _hashCode;

  @override
  int get hashCode {
    _hashCode ??= hashObjects(_list);
    return _hashCode!;
  }

P.S.: I have found 0 instances of people extending BuiltList on github.

cc @davidmorgan

@ahmednfwela ahmednfwela changed the title making BuiltList const making all collections const Jun 19, 2023
@ahmednfwela
Copy link
Author

We might want to change the name of the const constructor to something easier though, ideas are welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support "const" constructors for Build collections
1 participant