mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
8247605: Avoid array allocation when concatenating with empty string
Reviewed-by: redestad, plevart
This commit is contained in:
parent
e33ebc7f0a
commit
0a108f9ef2
2 changed files with 20 additions and 3 deletions
|
@ -28,11 +28,8 @@ import org.openjdk.jmh.annotations.Mode;
|
|||
import org.openjdk.jmh.annotations.OutputTimeUnit;
|
||||
import org.openjdk.jmh.annotations.Param;
|
||||
import org.openjdk.jmh.annotations.Scope;
|
||||
import org.openjdk.jmh.annotations.Setup;
|
||||
import org.openjdk.jmh.annotations.State;
|
||||
import org.openjdk.jmh.infra.Blackhole;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
|
@ -54,6 +51,8 @@ public class StringConcat {
|
|||
|
||||
public byte byteValue = (byte)-128;
|
||||
|
||||
public String emptyString = "";
|
||||
|
||||
@Benchmark
|
||||
public String concatConstInt() {
|
||||
return "string" + intValue;
|
||||
|
@ -64,6 +63,16 @@ public class StringConcat {
|
|||
return "string" + stringValue;
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public String concatEmptyRight() {
|
||||
return stringValue + emptyString;
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public String concatEmptyLeft() {
|
||||
return emptyString + stringValue;
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public String concatMethodConstString() {
|
||||
return "string".concat(stringValue);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue