Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

General clean-up and tweaks. #157

Merged
merged 2 commits into from
Sep 29, 2020
Merged

General clean-up and tweaks. #157

merged 2 commits into from
Sep 29, 2020

Conversation

lrhn
Copy link
Contributor

@lrhn lrhn commented Sep 28, 2020

Fixes some null-safety issues, usees some newer features (const classes can use mixins now),
and replaces unnecessary late with a dual constructor.

Fixes the CombinedList.iterator having potentially quadratic complexity
since the default list iterator does repeated indexing.

Ensure that interfaces returning an Iterable does not return a Set instead.

Fixes some null-safety issues, usees some newer features (const classes can use mixins now),
and replaces unnecessary `late` with a dual constructor.

Fixes the `CombinedList.iterator` having potentially quadratic complexity
since the default list iterator does repeated indexing.

Ensure that interfaces returning an `Iterable` does not return a `Set` instead.
class CombinedIterator<T> implements Iterator<T> {
/// The iterators that this combines, or `null` if done iterating.
///
/// Because this comes from a call to [Iterable.map], it's lazy and will
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I worry this comment will become stale now that it is no longer an implementation detail of a single library. Since it should still be private to the package this might not be a huge deal, but we should consider moving the comment to the constructor to be something like "iterators should not eagerly instantiate iterators which have not been reached".

Copy link
Contributor Author

@lrhn lrhn Sep 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is still an implementation detail, the class is not exported by the package.

I considered combining the combined list/iterable iterators in a single library, and making the helper private. Would you prefer that?

// Unfortunately, we can't use UnmodifiableSetMixin here, since const classes
// can't use mixins.
/// An unmodifiable, empty set that can have a const constructor.
/// An unmodifiable, empty set which can be constant.
class EmptyUnmodifiableSet<E> extends IterableBase<E>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[out of scope for this PR] Is this class buying value over const <E>{}? Should we consider deprecating it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not worth it any more. It's a valid superclass, but I can't see for what.
Yes, we should consider deprecating it.


/// The sets whose union is exposed through [set].
final _sets = <Set<E>>{};
final _sets;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a type?

Suggested change
final _sets;
final Set<Set<E>> _sets;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doh, yes. That's why I prefer always writing the types, they keep working when you remove the initializer!

@lrhn lrhn merged commit 898c839 into master Sep 29, 2020
@kevmoo kevmoo deleted the cleanup branch October 19, 2022 01:39
mosuem pushed a commit to dart-lang/core that referenced this pull request Oct 18, 2024
* General clean-up and tweaks.

Fixes some null-safety issues, usees some newer features (const classes can use mixins now),
and replaces unnecessary `late` with a dual constructor.

Fixes the `CombinedList.iterator` having potentially quadratic complexity
since the default list iterator does repeated indexing.

Ensure that interfaces returning an `Iterable` does not return a `Set` instead.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants