Skip to content

Commit

Permalink
Update getList and getMap return types
Browse files Browse the repository at this point in the history
This improves iteration performance by making `moveNext` and `current`
direct calls in kernel. google#902 does not have the same effect on `moveNext`
and `current` calls, this change is needed even with google#902.

This change was not possible before google#880 as users could override the
list and map types to types that are not `PbList`s or `PbMap`s.
  • Loading branch information
osa1 committed Nov 22, 2023
1 parent dcec2ed commit 514538f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 3 additions & 3 deletions protobuf/lib/src/protobuf/field_set.dart
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ class _FieldSet {
}

/// The implementation of a generated getter for repeated fields.
List<T> _$getList<T>(int index) {
PbList<T> _$getList<T>(int index) {
final value = _values[index];
if (value != null) return value;

Expand All @@ -387,9 +387,9 @@ class _FieldSet {
}

/// The implementation of a generated getter for map fields.
Map<K, V> _$getMap<K, V>(GeneratedMessage parentMessage, int index) {
PbMap<K, V> _$getMap<K, V>(GeneratedMessage parentMessage, int index) {
final value = _values[index];
if (value != null) return value as Map<K, V>;
if (value != null) return value as PbMap<K, V>;

final fi = _nonExtensionInfoByIndex(index) as MapFieldInfo<K, V>;
assert(fi.isMapField);
Expand Down
5 changes: 3 additions & 2 deletions protobuf/lib/src/protobuf/generated_message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -417,11 +417,12 @@ abstract class GeneratedMessage {

/// For generated code only.
/// @nodoc
List<T> $_getList<T>(int index) => _fieldSet._$getList<T>(index);
PbList<T> $_getList<T>(int index) => _fieldSet._$getList<T>(index);

/// For generated code only.
/// @nodoc
Map<K, V> $_getMap<K, V>(int index) => _fieldSet._$getMap<K, V>(this, index);
PbMap<K, V> $_getMap<K, V>(int index) =>
_fieldSet._$getMap<K, V>(this, index);

/// For generated code only.
/// @nodoc
Expand Down

0 comments on commit 514538f

Please sign in to comment.