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
Conversation
cc @nichite |
cc @rakudrama you might be interested. |
There was a problem hiding this 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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
protoc_plugin/CHANGELOG.md
Outdated
@@ -1,3 +1,9 @@ | |||
## 0.13.0 | |||
|
|||
* Breaking change: generated message classes now have a new instance method `createNewInstance` that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
createEmptyInstance ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no...
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
protoc_plugin/pubspec.yaml
Outdated
@@ -23,3 +23,7 @@ dev_dependencies: | |||
|
|||
executables: | |||
protoc-gen-dart: protoc_plugin | |||
|
|||
dependency_overrides: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove ?
There was a problem hiding this comment.
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', () { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
# Conflicts: # protobuf/CHANGELOG.md # protobuf/pubspec.yaml # protoc_plugin/CHANGELOG.md
extend tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PTAL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SLGTM
protobuf/CHANGELOG.md
Outdated
`GeneratedMessage` has a new abstract method: `createEmptyInstance()` that subclasses must | ||
implement. | ||
|
||
Proto files must be rebuilt using protoc_plugin 0.14.0 or newer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update protoc version dependency
protobuf/CHANGELOG.md
Outdated
@@ -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. | |||
|
|||
|
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improve this :-)
protoc_plugin/CHANGELOG.md
Outdated
@@ -1,3 +1,9 @@ | |||
## 0.13.0 | |||
|
|||
* Breaking change: generated message classes now have a new instance method `createNewInstance` that |
There was a problem hiding this comment.
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
No description provided.