From 514538f009aff36fd9095823a7684e3e74fb7e9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Sinan=20A=C4=9Facan?= Date: Wed, 22 Nov 2023 11:28:39 +0100 Subject: [PATCH 1/5] Update getList and getMap return types This improves iteration performance by making `moveNext` and `current` direct calls in kernel. #902 does not have the same effect on `moveNext` and `current` calls, this change is needed even with #902. This change was not possible before #880 as users could override the list and map types to types that are not `PbList`s or `PbMap`s. --- protobuf/lib/src/protobuf/field_set.dart | 6 +++--- protobuf/lib/src/protobuf/generated_message.dart | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/protobuf/lib/src/protobuf/field_set.dart b/protobuf/lib/src/protobuf/field_set.dart index 0c8b064fa..c2ac572cb 100644 --- a/protobuf/lib/src/protobuf/field_set.dart +++ b/protobuf/lib/src/protobuf/field_set.dart @@ -370,7 +370,7 @@ class _FieldSet { } /// The implementation of a generated getter for repeated fields. - List _$getList(int index) { + PbList _$getList(int index) { final value = _values[index]; if (value != null) return value; @@ -387,9 +387,9 @@ class _FieldSet { } /// The implementation of a generated getter for map fields. - Map _$getMap(GeneratedMessage parentMessage, int index) { + PbMap _$getMap(GeneratedMessage parentMessage, int index) { final value = _values[index]; - if (value != null) return value as Map; + if (value != null) return value as PbMap; final fi = _nonExtensionInfoByIndex(index) as MapFieldInfo; assert(fi.isMapField); diff --git a/protobuf/lib/src/protobuf/generated_message.dart b/protobuf/lib/src/protobuf/generated_message.dart index cc4d3d64b..d34dac4ad 100644 --- a/protobuf/lib/src/protobuf/generated_message.dart +++ b/protobuf/lib/src/protobuf/generated_message.dart @@ -417,11 +417,12 @@ abstract class GeneratedMessage { /// For generated code only. /// @nodoc - List $_getList(int index) => _fieldSet._$getList(index); + PbList $_getList(int index) => _fieldSet._$getList(index); /// For generated code only. /// @nodoc - Map $_getMap(int index) => _fieldSet._$getMap(this, index); + PbMap $_getMap(int index) => + _fieldSet._$getMap(this, index); /// For generated code only. /// @nodoc From 380ea6596454b8a77da2a8897a38e49dda5fecbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Sinan=20A=C4=9Facan?= Date: Wed, 22 Nov 2023 11:34:24 +0100 Subject: [PATCH 2/5] Update plugin --- protoc_plugin/lib/src/base_type.dart | 2 +- protoc_plugin/lib/src/protobuf_field.dart | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/protoc_plugin/lib/src/base_type.dart b/protoc_plugin/lib/src/base_type.dart index 6cc7ae5b0..c49810812 100644 --- a/protoc_plugin/lib/src/base_type.dart +++ b/protoc_plugin/lib/src/base_type.dart @@ -54,7 +54,7 @@ class BaseType { : prefixed; String getRepeatedDartType(FileGenerator fileGen) => - '$coreImportPrefix.List<${getDartType(fileGen)}>'; + '$protobufImportPrefix.PbList<${getDartType(fileGen)}>'; String getRepeatedDartTypeIterable(FileGenerator fileGen) => '$coreImportPrefix.Iterable<${getDartType(fileGen)}>'; diff --git a/protoc_plugin/lib/src/protobuf_field.dart b/protoc_plugin/lib/src/protobuf_field.dart index 8797d0ea7..b4ca5d1d0 100644 --- a/protoc_plugin/lib/src/protobuf_field.dart +++ b/protoc_plugin/lib/src/protobuf_field.dart @@ -146,7 +146,7 @@ class ProtobufField { final d = baseType.generator as MessageGenerator; final keyType = d._fieldList[0].baseType.getDartType(parent.fileGen!); final valueType = d._fieldList[1].baseType.getDartType(parent.fileGen!); - return '$coreImportPrefix.Map<$keyType, $valueType>'; + return '$protobufImportPrefix.PbMap<$keyType, $valueType>'; } if (isRepeated) return baseType.getRepeatedDartType(parent.fileGen!); return baseType.getDartType(parent.fileGen!); From 377342817fcceda954aa1e98c658438ab22c675c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Sinan=20A=C4=9Facan?= Date: Wed, 22 Nov 2023 11:37:39 +0100 Subject: [PATCH 3/5] Update changelog --- protoc_plugin/CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/protoc_plugin/CHANGELOG.md b/protoc_plugin/CHANGELOG.md index 566346ce9..6c8202f2a 100644 --- a/protoc_plugin/CHANGELOG.md +++ b/protoc_plugin/CHANGELOG.md @@ -1,8 +1,13 @@ ## 22.0.0-dev * Remove `PbEventMixin` mixin. ([#738]) +* Repeated fields now have `PbList` return type (instead of `List`), map fields + now have `PbMap` return type (instead of `Map`). ([#903]) + + This change requires protobuf-4.0.0. [#738]: https://github.com/google/protobuf.dart/issues/738 +[#903]: https://github.com/google/protobuf.dart/pull/903 ## 21.1.2 From f81521f0e3420dc4db7acafe60d7cc2868c5eca7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Sinan=20A=C4=9Facan?= Date: Thu, 23 Nov 2023 09:19:46 +0100 Subject: [PATCH 4/5] Update a cast --- protobuf/lib/src/protobuf/field_set.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protobuf/lib/src/protobuf/field_set.dart b/protobuf/lib/src/protobuf/field_set.dart index c2ac572cb..91d1c4c41 100644 --- a/protobuf/lib/src/protobuf/field_set.dart +++ b/protobuf/lib/src/protobuf/field_set.dart @@ -389,7 +389,7 @@ class _FieldSet { /// The implementation of a generated getter for map fields. PbMap _$getMap(GeneratedMessage parentMessage, int index) { final value = _values[index]; - if (value != null) return value as PbMap; + if (value != null) return value; final fi = _nonExtensionInfoByIndex(index) as MapFieldInfo; assert(fi.isMapField); From ddbe1793c179fc8870fbd1e89c8222439087b96b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Sinan=20A=C4=9Facan?= Date: Thu, 23 Nov 2023 09:26:47 +0100 Subject: [PATCH 5/5] Rewording --- protoc_plugin/CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/protoc_plugin/CHANGELOG.md b/protoc_plugin/CHANGELOG.md index 6c8202f2a..0684291b0 100644 --- a/protoc_plugin/CHANGELOG.md +++ b/protoc_plugin/CHANGELOG.md @@ -1,8 +1,8 @@ ## 22.0.0-dev * Remove `PbEventMixin` mixin. ([#738]) -* Repeated fields now have `PbList` return type (instead of `List`), map fields - now have `PbMap` return type (instead of `Map`). ([#903]) +* Type of repeated fields is now `PbList` (instead of `List`), type of map + fields is now `PbMap` (instead of `Map`). ([#903]) This change requires protobuf-4.0.0.