mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +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) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
|
@ -1016,18 +1016,12 @@ final class StringUTF16 {
|
|||
public static String stripLeading(byte[] value) {
|
||||
int length = value.length >>> 1;
|
||||
int left = indexOfNonWhitespace(value);
|
||||
if (left == length) {
|
||||
return "";
|
||||
}
|
||||
return (left != 0) ? newString(value, left, length - left) : null;
|
||||
}
|
||||
|
||||
public static String stripTrailing(byte[] value) {
|
||||
int length = value.length >>> 1;
|
||||
int right = lastIndexOfNonWhitespace(value);
|
||||
if (right == 0) {
|
||||
return "";
|
||||
}
|
||||
return (right != length) ? newString(value, 0, right) : null;
|
||||
}
|
||||
|
||||
|
@ -1132,6 +1126,9 @@ final class StringUTF16 {
|
|||
}
|
||||
|
||||
public static String newString(byte[] val, int index, int len) {
|
||||
if (len == 0) {
|
||||
return "";
|
||||
}
|
||||
if (String.COMPACT_STRINGS) {
|
||||
byte[] buf = compress(val, index, len);
|
||||
if (buf != null) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue