Comment #2 on issue 460 by dav.co...@gmail.com: Add isDefault() to Java
Message interface as a fast means to verify whether it is a default instance
http://code.google.com/p/protobuf/issues/detail?id=460
1. It is the basic functionality and the use case to check for Message, in
fact, for any object, emptiness/defaultness.
2. It is used extensively in the protobuf project itself, just look for
message == message.getDefaultInstanceForType() pattern.
3. In addition, it's usually been used in performance critical places, like
Builder#mergeFrom. Even 1 such a place in the code may result in thousands
calls or more; don't trust me - profile for yourself.
4. Outside of the protobuf itself, it has to be used all over the place,
for example, if one needs to sift through empty/default messages, in object
datastores that hold some messages, and so on...
5. As I mentioned earlier, all DynamicMessage based classes will have to
use equals()
while GeneratedMessage based ones want to use identity checks, and there
is no guarantee it will always be the case. The equals() is relatively
slow; both methods are cumbersome to use; the user will have to do
instanceof to differentiate between DynamicMessage and the likes, and the
GeneratedMessage.
6. You go in great length to optimize performance, this one is very
benefitial overall.
7. There is no cons here, because the Message/Builder interface already
changed in this release, so the isDefault() can go along nicely. It will
make the API a bit easier to use, and adds to its logical completeness.
8. The implementation is much simpler than the time we've spent discussing
this again
- I think I described all the benefits and the implementation at the start
of this issue.
Regards,
David
--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings
--
You received this message because you are subscribed to the Google Groups "Protocol
Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at http://groups.google.com/group/protobuf?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.