RFR 8214971 : Replace use of string.equals("") with isEmpty()

Roger Riggs roger.riggs at oracle.com
Thu Dec 6 21:51:32 UTC 2018


Hi Jim,

Yes, it is likely that the compiler gets to the same optimization.
But we save a little bit too by not making the compiler work so hard.
And it helps during startup before the compiler kicks in.

IntelliJ did the hard work and a full CI build/test is in progress.

And isEmpty reads better.

Thanks, Roger

On 12/6/18 3:27 PM, Jim Laskey wrote:
> I assume you automated this change, might be worthwhile to automate a verification (compare the -+ pairs.) Eyeballing the patch it seems complete, one comment changed as well.
>
> Question: Is it probably that vm optimizes .equals(“”) to .isEmpty() and there is no net win, ie., more of an esthetic clean up than for performance?
>
> Cheers,
>
> — Jim
>
>
>
>> On Dec 6, 2018, at 4:04 PM, Roger Riggs <Roger.Riggs at oracle.com> wrote:
>>
>> Please review changing string.equals("") to string.isEmpty().
>> isEmpty is preferred, performs better and is easier to optimize.
>>
>> The change is a literal substitution in all files and only in these modules:
>>
>>    java.base
>>    java.logging
>>    java.management
>>    java.management.rmi
>>    java.naming
>>    java.net.http
>>    java.prefs
>>    java.rmi
>>    java.scripting
>>    java.sql
>>    java.sql.rowset
>>    java.xml
>>    jdk.jartool
>>    jdk.javadoc
>>    jdk.jcmd
>>    jdk.jconsole
>>    jdk.management.agent
>>    jdk.naming.dns
>>    jdk.rmic
>>
>>
>> Webrev:
>> http://cr.openjdk.java.net/~rriggs/webrev-string-isempty-8214971-1/
>>
>> Issue:
>>    https://bugs.openjdk.java.net/browse/JDK-8214971
>>
>> Thanks, Roger



More information about the core-libs-dev mailing list