Skip to content
This repository has been archived by the owner on Oct 16, 2024. It is now read-only.

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant