Aaand forgot to reply all. Apologies. Cheers, -pwr
---------- Forwarded message ---------- From: Daniel Augustin Pavel <daniel.pa...@gmail.com> Date: Fri, Sep 25, 2009 at 19:04 Subject: Re: Java generated code: faster equals() and hashCode() To: Brice Figureau <brice...@daysofwonder.com> On Fri, Sep 25, 2009 at 18:12, Brice Figureau <brice...@daysofwonder.com> wrote: > I think it would be safer to do this: > + printer->Print( > + "if (otherObject == this) return true;\n" > + "if (!(otherObject instanceof $classname$)) return false;\n" > + "if (hashCode() != otherObject.hashCode()) return false;\n" > + "$classname$ other = ($classname$) otherObject;\n", > + "classname", descriptor_->name()); > > (I reversed the hashCode test and the instanceof test) > This way if I happen to pbObject.equals(null) it won't throw a > NullPointerException, but just say they're not equals (which they are, > right?) Quite right. I was under the impression that most equals() implementation happily throw NPE when comparinga against a null, so did not think much of it. Checked now more closely a few classes in the JDK, and I was obviously wrong. I've attached the fixed patch. Cheers, -pwr -- Time is an illusion. Lunchtime doubly so. -- Douglas Adams --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Protocol Buffers" group. To post to this group, send email to protobuf@googlegroups.com To unsubscribe from this group, send email to protobuf+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/protobuf?hl=en -~----------~----~----~----~------~----~------~--~---
improved_equals_2.diff
Description: Binary data