8240094: Optimize empty substring handling

Reviewed-by: redestad, igerasim, jlaskey
This commit is contained in:
Sergei Tsypanov 2020-02-26 21:24:02 +01:00 committed by Claes Redestad
parent 257de28b2c
commit f729514ebd
4 changed files with 23 additions and 18 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -28,6 +28,9 @@ import java.util.concurrent.TimeUnit;
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@Fork(value = 3)
@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@State(Scope.Benchmark)
public class StringSubstring {
@ -42,4 +45,12 @@ public class StringSubstring {
public String from26toEnd1() {
return s.substring(26, s.length());
}
/**
* An empty substring should not allocate a new String
*/
@Benchmark
public String empty() {
return s.substring(17, 17);
}
}