java.lang.String#contentEquals(CharSequence) suboptimal?
Jesús Viñuales
serverperformance at gmail.com
Mon Jan 4 16:42:35 UTC 2010
Hi Alex,
String.equals already performs that instanceof comparison, and is one of the first to be inlined by the hotspot. What I would do is to turn it... "this.equals(cs)" instead of "cs.equals(this)".
Which would only improve performance if you have classes implementing CharSequence other than String, StringBuilder and StringBuffer... Anyway, does anyone know if the contentEquals method is actually used out there? (at least it isn't inside the JDK source code).
Regards,
--Jesus
Alexander Veit wrote:
> Hi,
>
> it seems that
>
> if (cs.equals(this))
> return true;
>
> should be replaced with
>
> if (cs instanceof String)
> return cs.equals(this);
>
> or completely left out.
>
> Does anyone agree?
>
> --
> Cheers,
> Alex
More information about the core-libs-dev
mailing list