Skip to content

Commit 07eed6e

Browse files
authored
Generalize argument type of PbList.from from List<T> to Iterable<T> (#1054)
This is more consistent with `List.from` and also more efficient as we can avoid redundant `List` allocations when we have an `Iterable` instead of a `List`. This commonly happens when we create a `PbList` from a chain of `map`, `where` etc. calls. Also update the the factory body to use `List.of` instead of `List.from` as we know the `Iterable`'s element type. (`List.from` takes `Iterable<dynamic>`, `List.of` takes `Iterable<T>`) cl/810421932
1 parent 0447bd2 commit 07eed6e

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

protobuf/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44
* Fix unknown enum handling in `GeneratedMessage.mergeFromProto3Json` when
55
the `ignoreUnknownFields` optional argument is `true`. ([#853])
66
* Add `BuilderInfo` methods to support protoc-plugin 23.0.0. ([#1047])
7+
* Generalize argument type of `PbList.from` from `List<T>` to `Iterable<T>`.
8+
([#1054])
79

810
[#742]: https://github.com/google/protobuf.dart/pull/742
911
[#853]: https://github.com/google/protobuf.dart/pull/853
1012
[#1047]: https://github.com/google/protobuf.dart/pull/1047
13+
[#1054]: https://github.com/google/protobuf.dart/pull/1054
1114

1215
## 4.2.0
1316

protobuf/lib/src/protobuf/pb_list.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ class PbList<E> extends ListBase<E> {
4040
_check = _checkNotNull,
4141
_isReadOnly = true;
4242

43-
PbList.from(List<E> from)
44-
: _wrappedList = List<E>.from(from),
43+
PbList.from(Iterable<E> from)
44+
: _wrappedList = List<E>.of(from),
4545
_check = _checkNotNull;
4646

4747
@override

0 commit comments

Comments
 (0)