mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
8240094: Optimize empty substring handling
Reviewed-by: redestad, igerasim, jlaskey
This commit is contained in:
parent
257de28b2c
commit
f729514ebd
4 changed files with 23 additions and 18 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue