Remove redundant calls of toString()
david.holmes at oracle.com
Tue Apr 29 09:58:59 UTC 2014
On 29/04/2014 7:40 PM, Andrew Haley wrote:
> On 04/28/2014 07:57 AM, David Holmes wrote:
>> On 28/04/2014 1:05 PM, Otávio Gonçalves de Santana wrote:
>>> In my opinion not, because Objects.requireNonNull is more readable than
>>> just string.toString. This way is more understandable which field is
>>> required and doesn't impact on performance.
>> An invocation of requireNonNull is potentially more expensive than the
>> implicit null check that happens with foo.toString().
> It's also potentially cheaper: a cbnz versus a fetch from memory with a
> few cycles pipeline delay.
Can you elaborate please? AFAIK implicit null checks have no overhead
when the object reference is not null.
Interpreted it is slower and the bytecode footprint is larger.
IIRC the guidelines for use of requireNonNull in the JDK code was for
replacing explicit null checks in precondition checking, not implicit ones.
Anyway I don't find these changes compelling. YMMV.
More information about the core-libs-dev