Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change GeneratedMessage.toBuilder() to only make a shallow copy #145

Merged
merged 11 commits into from Jan 8, 2019

Conversation

sigurdm
Copy link
Collaborator

@sigurdm sigurdm commented Dec 11, 2018

No description provided.

@sigurdm
Copy link
Collaborator Author

sigurdm commented Dec 11, 2018

cc @nichite

@sigurdm
Copy link
Collaborator Author

sigurdm commented Dec 11, 2018

cc @rakudrama you might be interested.

Copy link
Member

@szakarias szakarias left a comment

Choose a reason for hiding this comment

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

LGTM

_values.setRange(0, original._values.length, original._values);
for (int index = 0; index < _meta.byIndex.length; index++) {
FieldInfo fieldInfo = _meta.byIndex[index];
if (fieldInfo.isRepeated) {
Copy link
Member

Choose a reason for hiding this comment

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

Do something similiar for map fields?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

protobuf/lib/src/protobuf/generated_message.dart Outdated Show resolved Hide resolved
@@ -1,3 +1,9 @@
## 0.13.0

* Breaking change: generated message classes now have a new instance method `createNewInstance` that
Copy link
Member

Choose a reason for hiding this comment

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

createEmptyInstance ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

Copy link
Member

Choose a reason for hiding this comment

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

no...

Copy link
Contributor

Choose a reason for hiding this comment

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

Please try to avoid adding instance methods.

I would like to do a compiler optimization where FooMessage is replaced with GeneratedMessage unless there is a test like 'is FooMessage'.
This will remove many of the thousands of generated classes, but it is only possible if the generated message classes have instance methods that are always inlined (the field get/set/has methods are resolved to one target and inlined, leaving the class 'empty').
createNewInstance is defined in the base class and overridden so is not inlined.

This can be fixed by storing FooMessage.create in the BuilderInfo, and using it from there.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sad that I got to release a version before seeing your comment. :(

We have the same problem with clone() no?

Could we store the FooMessage.create() method in BuilderInfo as you suggest, and then make this method non-abstract and use that?

@@ -23,3 +23,7 @@ dev_dependencies:

executables:
protoc-gen-dart: protoc_plugin

dependency_overrides:
Copy link
Member

Choose a reason for hiding this comment

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

Remove ?

Copy link
Member

Choose a reason for hiding this comment

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

Update the dependency above.

import 'package:test/test.dart';

main() {
test('frozen behavior', () {
Copy link
Member

Choose a reason for hiding this comment

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

Add tests for list and maps?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

Copy link
Collaborator Author

@sigurdm sigurdm left a comment

Choose a reason for hiding this comment

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

PTAL

Copy link
Member

@szakarias szakarias left a comment

Choose a reason for hiding this comment

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

SLGTM

`GeneratedMessage` has a new abstract method: `createEmptyInstance()` that subclasses must
implement.

Proto files must be rebuilt using protoc_plugin 0.14.0 or newer.
Copy link
Member

Choose a reason for hiding this comment

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

update protoc version dependency

@@ -8,6 +17,7 @@
Map fields are now represented as Dart maps and are accessed through a getter with the same name as the map field.
To use the map support, use Dart protoc_plugin version 11.0 or newer.


Copy link
Member

Choose a reason for hiding this comment

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

newline

// for sub-messages, instead of cloning everything here.
GeneratedMessage toBuilder() => clone();
///
/// The lists for repeated fields are also copied.
Copy link
Member

Choose a reason for hiding this comment

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

Improve this :-)

@@ -1,3 +1,9 @@
## 0.13.0

* Breaking change: generated message classes now have a new instance method `createNewInstance` that
Copy link
Member

Choose a reason for hiding this comment

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

no...

# Conflicts:
#	protobuf/CHANGELOG.md
#	protobuf/pubspec.yaml
#	protoc_plugin/CHANGELOG.md
#	protoc_plugin/pubspec.yaml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants