[sdk] Use {List,Set}.of() instead of {List,Set}.from()

The `{List,Set}.from` take an `Iterable` and perform a `is Iterable<T>`
type check inside.

The `{List,Set}.of` in comparison take a `Iterable<T>` and do not
perform a type check.

TEST=ci

CoreLibraryReviewExempt: Optimizes implementation, no API changes.
Change-Id: I99f138bfbdedac15752b01bfdf0bbec258bb9107
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/374561
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
This commit is contained in:
Martin Kustermann 2024-07-04 10:32:30 +00:00
parent 10742d9a12
commit 6fae002f59
12 changed files with 27 additions and 27 deletions

View file

@ -305,7 +305,7 @@ library from "org-dartlang-test:///main.dart" as main {
dart.core::int listLength = this.{dart.core::List::length}{dart.core::int};
end == null ?{dart.core::int?} end = listLength : null;
dart.core::RangeError::checkValidRange(start, end{dart.core::int}, listLength);
return dart.core::List::from<dart.core::int>(this.{dart.collection::ListBase::getRange}(start, end{dart.core::int}){(dart.core::int, dart.core::int) → dart.core::Iterable<dart.core::int>});
return dart.core::List::of<dart.core::int>(this.{dart.collection::ListBase::getRange}(start, end{dart.core::int}){(dart.core::int, dart.core::int) → dart.core::Iterable<dart.core::int>});
}
method /* from org-dartlang-sdk:///sdk/lib/collection/list.dart */ getRange(dart.core::int start, dart.core::int end) → dart.core::Iterable<dart.core::int> {
dart.core::RangeError::checkValidRange(start, end, this.{dart.core::List::length}{dart.core::int});

View file

@ -305,7 +305,7 @@ library from "org-dartlang-test:///main.dart" as main {
dart.core::int listLength = this.{dart.core::List::length}{dart.core::int};
end == null ?{dart.core::int?} end = listLength : null;
dart.core::RangeError::checkValidRange(start, end{dart.core::int}, listLength);
return dart.core::List::from<dart.core::int>(this.{dart.collection::ListBase::getRange}(start, end{dart.core::int}){(dart.core::int, dart.core::int) → dart.core::Iterable<dart.core::int>});
return dart.core::List::of<dart.core::int>(this.{dart.collection::ListBase::getRange}(start, end{dart.core::int}){(dart.core::int, dart.core::int) → dart.core::Iterable<dart.core::int>});
}
method /* from org-dartlang-sdk:///sdk/lib/collection/list.dart */ getRange(dart.core::int start, dart.core::int end) → dart.core::Iterable<dart.core::int> {
dart.core::RangeError::checkValidRange(start, end, this.{dart.core::List::length}{dart.core::int});

View file

@ -309,7 +309,7 @@ abstract class _MyList&Object&ListMixin<E extends core::Object? = dynamic> exten
core::int listLength = this.{core::List::length}{core::int};
end == null ?{core::int?} end = listLength : null;
core::RangeError::checkValidRange(start, end{core::int}, listLength);
return core::List::from<self::_MyList&Object&ListMixin::E%>(this.{col::ListBase::getRange}(start, end{core::int}){(core::int, core::int) → core::Iterable<self::_MyList&Object&ListMixin::E%>});
return core::List::of<self::_MyList&Object&ListMixin::E%>(this.{col::ListBase::getRange}(start, end{core::int}){(core::int, core::int) → core::Iterable<self::_MyList&Object&ListMixin::E%>});
}
method /* from org-dartlang-sdk:///sdk/lib/collection/list.dart */ getRange(core::int start, core::int end) → core::Iterable<self::_MyList&Object&ListMixin::E%> {
core::RangeError::checkValidRange(start, end, this.{core::List::length}{core::int});

View file

@ -376,7 +376,7 @@ abstract class _CustomList&Object&ListMixin<E extends core::Object? = dynamic> e
core::int listLength = this.{core::List::length}{core::int};
end == null ?{core::int?} end = listLength : null;
core::RangeError::checkValidRange(start, end{core::int}, listLength);
return core::List::from<cac::_CustomList&Object&ListMixin::E%>(this.{col::ListBase::getRange}(start, end{core::int}){(core::int, core::int) → core::Iterable<cac::_CustomList&Object&ListMixin::E%>});
return core::List::of<cac::_CustomList&Object&ListMixin::E%>(this.{col::ListBase::getRange}(start, end{core::int}){(core::int, core::int) → core::Iterable<cac::_CustomList&Object&ListMixin::E%>});
}
method /* from org-dartlang-sdk:///sdk/lib/collection/list.dart */ getRange(core::int start, core::int end) → core::Iterable<cac::_CustomList&Object&ListMixin::E%> {
core::RangeError::checkValidRange(start, end, this.{core::List::length}{core::int});

View file

@ -309,7 +309,7 @@ abstract class _A&Object&ListMixin extends core::Object implements col::ListBase
core::int listLength = this.{core::List::length}{core::int};
end == null ?{core::int?} end = listLength : null;
core::RangeError::checkValidRange(start, end{core::int}, listLength);
return core::List::from<core::int>(this.{col::ListBase::getRange}(start, end{core::int}){(core::int, core::int) → core::Iterable<core::int>});
return core::List::of<core::int>(this.{col::ListBase::getRange}(start, end{core::int}){(core::int, core::int) → core::Iterable<core::int>});
}
method /* from org-dartlang-sdk:///sdk/lib/collection/list.dart */ getRange(core::int start, core::int end) → core::Iterable<core::int> {
core::RangeError::checkValidRange(start, end, this.{core::List::length}{core::int});

View file

@ -309,7 +309,7 @@ abstract class _NegativeLengthList&Object&ListMixin<E extends core::Object? = dy
core::int listLength = this.{core::List::length}{core::int};
end == null ?{core::int?} end = listLength : null;
core::RangeError::checkValidRange(start, end{core::int}, listLength);
return core::List::from<self::_NegativeLengthList&Object&ListMixin::E%>(this.{col::ListBase::getRange}(start, end{core::int}){(core::int, core::int) → core::Iterable<self::_NegativeLengthList&Object&ListMixin::E%>});
return core::List::of<self::_NegativeLengthList&Object&ListMixin::E%>(this.{col::ListBase::getRange}(start, end{core::int}){(core::int, core::int) → core::Iterable<self::_NegativeLengthList&Object&ListMixin::E%>});
}
method /* from org-dartlang-sdk:///sdk/lib/collection/list.dart */ getRange(core::int start, core::int end) → core::Iterable<self::_NegativeLengthList&Object&ListMixin::E%> {
core::RangeError::checkValidRange(start, end, this.{core::List::length}{core::int});

View file

@ -290,11 +290,11 @@ base mixin _IntListMixin on _TypedListBase implements TypedDataList<int> {
Iterator<int> get iterator => new _TypedListIterator<int>(this);
List<int> toList({bool growable = true}) {
return new List<int>.from(this, growable: growable);
return new List<int>.of(this, growable: growable);
}
Set<int> toSet() {
return new Set<int>.from(this);
return new Set<int>.of(this);
}
void forEach(void f(int element)) {
@ -625,11 +625,11 @@ base mixin _DoubleListMixin on _TypedListBase implements TypedDataList<double> {
Iterator<double> get iterator => new _TypedListIterator<double>(this);
List<double> toList({bool growable = true}) {
return new List<double>.from(this, growable: growable);
return new List<double>.of(this, growable: growable);
}
Set<double> toSet() {
return new Set<double>.from(this);
return new Set<double>.of(this);
}
void forEach(void f(double element)) {
@ -1012,11 +1012,11 @@ base mixin _Float32x4ListMixin on _TypedListBase
Iterator<Float32x4> get iterator => new _TypedListIterator<Float32x4>(this);
List<Float32x4> toList({bool growable = true}) {
return new List<Float32x4>.from(this, growable: growable);
return new List<Float32x4>.of(this, growable: growable);
}
Set<Float32x4> toSet() {
return new Set<Float32x4>.from(this);
return new Set<Float32x4>.of(this);
}
void forEach(void f(Float32x4 element)) {
@ -1350,11 +1350,11 @@ base mixin _Int32x4ListMixin on _TypedListBase
Iterator<Int32x4> get iterator => new _TypedListIterator<Int32x4>(this);
List<Int32x4> toList({bool growable = true}) {
return new List<Int32x4>.from(this, growable: growable);
return new List<Int32x4>.of(this, growable: growable);
}
Set<Int32x4> toSet() {
return new Set<Int32x4>.from(this);
return new Set<Int32x4>.of(this);
}
void forEach(void f(Int32x4 element)) {
@ -1689,11 +1689,11 @@ base mixin _Float64x2ListMixin on _TypedListBase
Iterator<Float64x2> get iterator => new _TypedListIterator<Float64x2>(this);
List<Float64x2> toList({bool growable = true}) {
return new List<Float64x2>.from(this, growable: growable);
return new List<Float64x2>.of(this, growable: growable);
}
Set<Float64x2> toSet() {
return new Set<Float64x2>.from(this);
return new Set<Float64x2>.of(this);
}
void forEach(void f(Float64x2 element)) {

View file

@ -446,7 +446,7 @@ class JSArrayImpl<T extends JSAny?> implements List<T> {
List<T>.of(this, growable: growable);
@override
Set<T> toSet() => Set<T>.from(this);
Set<T> toSet() => Set<T>.of(this);
@override
Iterator<T> get iterator => JSArrayImplIterator<T>(this);

View file

@ -473,11 +473,11 @@ mixin _IntListMixin implements List<int> {
}
List<int> toList({bool growable = true}) {
return List<int>.from(this, growable: growable);
return List<int>.of(this, growable: growable);
}
Set<int> toSet() {
return Set<int>.from(this);
return Set<int>.of(this);
}
void forEach(void f(int element)) {
@ -1687,11 +1687,11 @@ mixin _DoubleListMixin implements List<double> {
}
List<double> toList({bool growable = true}) {
return List<double>.from(this, growable: growable);
return List<double>.of(this, growable: growable);
}
Set<double> toSet() {
return Set<double>.from(this);
return Set<double>.of(this);
}
void forEach(void f(double element)) {

View file

@ -51,7 +51,7 @@ abstract class WasmListBase<E> extends ListBase<E> {
}
@pragma("wasm:prefer-inline")
List<E> toList({bool growable = true}) => List.from(this, growable: growable);
List<E> toList({bool growable = true}) => List.of(this, growable: growable);
}
@pragma("wasm:entry-point")

View file

@ -1529,11 +1529,11 @@ mixin _IntListMixin implements TypedDataList<int> {
Iterator<int> get iterator => _TypedListIterator<int>(this);
List<int> toList({bool growable = true}) {
return List<int>.from(this, growable: growable);
return List<int>.of(this, growable: growable);
}
Set<int> toSet() {
return Set<int>.from(this);
return Set<int>.of(this);
}
void forEach(void f(int element)) {
@ -1923,11 +1923,11 @@ mixin _DoubleListMixin implements TypedDataList<double> {
Iterator<double> get iterator => _TypedListIterator<double>(this);
List<double> toList({bool growable = true}) {
return List<double>.from(this, growable: growable);
return List<double>.of(this, growable: growable);
}
Set<double> toSet() {
return Set<double>.from(this);
return Set<double>.of(this);
}
void forEach(void f(double element)) {

View file

@ -349,7 +349,7 @@ abstract mixin class ListBase<E> implements List<E> {
end ??= listLength;
RangeError.checkValidRange(start, end, listLength);
return List.from(getRange(start, end));
return List.of(getRange(start, end));
}
Iterable<E> getRange(int start, int end) {