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

mergeFrom should support partials #444

Open
alicederyn opened this issue Jan 12, 2022 · 0 comments
Open

mergeFrom should support partials #444

alicederyn opened this issue Jan 12, 2022 · 0 comments

Comments

@alicederyn
Copy link
Collaborator

Currently, merging from a partial will raise an UnsupportedOperationException if any required field is unset. This was to avoid a performance penalty in non-test code.

However, I think we can use the same trick that worked for the static toBuilder method: cast to a common interface, then call a method (say, mergeInto) that has different implementations in the Value and Partial types. If the cast fails, fall back to the old code path. This avoids a performance hit because hotspot will determine a single type is used in practice and optimize for it.

One risk in doing this is that people might start using partials in production code for this behaviour. We would need to document the preferred alternative (namely, merge from a partially filled Builder).

This still doesn't make partiality "stick" to the builder in the same way it does for toBuilder, though that also doesn't happen if you use mergeFrom(partial.toBuilder()). It may still make testing sufficiently easier that it is worth doing.

@alicederyn alicederyn changed the title mergeFromb should support partials mergeFrom should support partials Jan 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant