'\"' can be written as '"': com_sun.diff:209:+ sb.append(' ').append(nodeName).append("=\"").append(att.getNodeValue()).append('\"'); java_lang.diff:31:+ sb.append('\"').append(getThreadName()).append('\"') java_security.diff:78:+ .append('\"'); sun_security.diff:95:+ sb.append(principalInfo[i][0]).append(' ').append('\"').append(principalInfo[i][1]).append('\"'); sun_security.diff:108:+ .append('\"'); sun_security.diff:122:+ sb.append(X500PRINCIPAL).append(" \"").append(suffix).append('\"'); sun_security.diff:312:+ retval.append('\"').append(sbuffer.toString()).append('\"');
Still using append("."): java_security.diff:107:+ sb.append("\n").append(type).append(" Cert Path: length = ").append(getCertificates().size()).append(".\n"); java_security.diff:148:+ sb.append(" serverName: ").append(serverName).append("\n"); javax_swing.diff:79:+ sb.append(getClass().getName()).append(" ").append(Integer.toString(hashCode())); sun_security.diff:419:+ sb.append("X.509 CRL v").append(version + 1).append("\n"); I only read the security related files, but I grep for the two groups above. Also, it's better to put rb.getString(...) to one line sun_security.diff:268:+ sb.append('\n').append(tab).append(rb.getString( sun_security.diff:273:+ sb.append('\n').append(tab).append(rb.getString( And some lines are too long. Thanks Max On Aug 11, 2014, at 11:29, Otávio Gonçalves de Santana <otavioj...@java.net> wrote: > Done. > > https://dl.dropboxusercontent.com/u/16109193/open_jdk/string_builder_concat_2.zip > > obs: stay the 2 chars to better performance. > > > On Sun, Aug 10, 2014 at 8:03 PM, Claes Redestad <claes.redes...@oracle.com> > wrote: > +1 > > Some suggestions (mostly nits): > > - in places like src/share/classes/java/util/regex/Pattern.java you > introducesingle-char > strings which might use a char instead: > > - result.append("|"+next); > + result.append('|').append(next); > > - in places like src/share/classes/sun/security/provider/PolicyFile.java > you end up with a sequence of String literal appends which could be merged > into one: > > - sb.append(principalInfo[i][0] + " " + > - "\"" + principalInfo[i][1] + "\""); > + sb.append(principalInfo[i][0]).append(" \"") > + .append(principalInfo[i][1]).append('"'); > > - in some places like src/share/classes/java/text/ChoiceFormat.java > you end up doing append(""). I guess the empty string concatenation was > used as a form > of primitive-to-string coercion and was probably always redundant already, > but care needs > to be taken that doing the append directly behave as intended. > > I think it should be safe to just remove the empty string append in most > cases: > > - result.append(""+choiceLimits[i]); > + result.append(choiceLimits[i]); > > Thanks! > > /Claes > > On 2014-08-10 23:33, Otávio Gonçalves de Santana wrote: > *Motivation:* Make another append instead of concat String inside of append > > parameter in StringBuilder class. To avoid an extra StringBuilder created > for the purpose of concatenating. So it will save memory and will faster > than concat String. > Doing a code to benchMark[1], the result is: > > Benchmark Mode Samples > Mean Mean error Units > m.StringBuilderConcatBenchMark.stringBuilder thrpt 10 > 6317444.705 108673.584 ops/s > m.StringBuilderConcatBenchMark.stringBuilderWithConcat thrpt 10 > 3354554.435 68353.924 ops/s > > The webrev of all code is: > https://dl.dropboxusercontent.com/u/16109193/open_jdk/string_builder_concat.zip > <https://dl.dropboxusercontent.com/u/16109193/open_jdk/string_builder_concat.zip> > > [1] > > @State(Scope.Thread) > @OutputTimeUnit(TimeUnit.SECONDS) > public class StringBuilderConcatBenchMark { > > > private static final String F = "!!!!"; > private static final String E = " running in Java "; > private static final String D = " in the code "; > private static final String C = " to try impact "; > private static final String B = " with some text "; > private static final String A = "Doing a test"; > > @GenerateMicroBenchmark > public void stringBuilder(BlackHole bh) { > bh.consume(createBuilder(A, B, C, D, E, F)); > } > > @GenerateMicroBenchmark > public void stringBuilderWithConcat(BlackHole bh) { > bh.consume(createBuilderWithConcat(A, B, C, D, E, F)); > } > > private StringBuilder createBuilder(String... values) { > StringBuilder text = new StringBuilder(); > text.append(values[0]).append(values[1]) > .append(values[2]).append(values[3]) > .append(values[4]).append(values[5]); > return text; > } > private StringBuilder createBuilderWithConcat(String... values) { > StringBuilder text = new StringBuilder(); > text.append(values[0] + values[1]) > .append(values[2] + values[3]) > .append(values[4]+ values[5]); > return text; > } > } > > > > > > -- > Otávio Gonçalves de Santana > > blog: http://otaviosantana.blogspot.com.br/ > twitter: http://twitter.com/otaviojava > site: http://about.me/otaviojava > 55 (11) 98255-3513 > <sun_tools.diff><sun_security.diff><sun_net.diff><sun_management.diff><sun_launcher.diff><sun_font.diff><javax_swing.diff><javax_sound.diff><javax_security.diff><javax_naming.diff><javax_crypto.diff><javax_,anagement.diff><java_util.diff><java_text.diff><java_security.diff><java_rmi.diff><java_lang.diff><com_sun.diff>