java.lang.String#contentEquals(CharSequence) suboptimal? (original) (raw)
Jesús Viñuales serverperformance at gmail.com
Mon Jan 4 16:42:35 UTC 2010
- Previous message: java.lang.String#contentEquals(CharSequence) suboptimal?
- Next message: java.lang.String#contentEquals(CharSequence) suboptimal?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Previous message: java.lang.String#contentEquals(CharSequence) suboptimal?
- Next message: java.lang.String#contentEquals(CharSequence) suboptimal?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]