Hi Otávio!

A few days ago I've posted another cleanup request, which included modifications to src/share/classes/sun/net/www/MimeEntry.java
http://mail.openjdk.java.net/pipermail/core-libs-dev/2014-August/028131.html

As our changes overlap, one should be reverted back.
I believe using StringJoiner makes MimeEntry#toString() a bit cleaner.
What do you think?

Sincerely yours,
Ivan

On 11.08.2014 1: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;
}
}


Reply via email to