Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/java.base/share/classes/java/lang/StringLatin1.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ static int getChars(int i, int index, byte[] buf) {
charPos -= 2;
writeDigitPair(buf, charPos, -i);
} else {
buf[--charPos] = (byte)('0' - i);
putChar(buf, --charPos, '0' - i);
}

if (negative) {
buf[--charPos] = (byte)'-';
putChar(buf, --charPos, '-');
}
return charPos;
}
Expand Down Expand Up @@ -185,19 +185,19 @@ static int getChars(long i, int index, byte[] buf) {
charPos -= 2;
writeDigitPair(buf, charPos, -i2);
} else {
buf[--charPos] = (byte)('0' - i2);
putChar(buf, --charPos, '0' - i2);
}

if (negative) {
buf[--charPos] = (byte)'-';
putChar(buf, --charPos, '-');
}
return charPos;
}

private static void writeDigitPair(byte[] buf, int charPos, int value) {
short pair = DecimalDigits.digitPair(value);
buf[charPos] = (byte)(pair);
buf[charPos + 1] = (byte)(pair >> 8);
putChar(buf, charPos , (byte)(pair));
putChar(buf, charPos + 1, (byte)(pair >> 8));
}

public static void getChars(byte[] value, int srcBegin, int srcEnd, char[] dst, int dstBegin) {
Expand Down Expand Up @@ -849,8 +849,8 @@ static void putCharsAt(byte[] val, int index, int c1, int c2, int c3, int c4, in
}

public static void putChar(byte[] val, int index, int c) {
//assert (canEncode(c));
val[index] = (byte)(c);
assert index >= 0 && index < length(val) : "Trusted caller missed bounds check";
UNSAFE.putByte(val, Unsafe.ARRAY_BYTE_BASE_OFFSET + index, (byte) c);
}

public static char getChar(byte[] val, int index) {
Expand Down
50 changes: 50 additions & 0 deletions test/micro/org/openjdk/bench/java/lang/StringBuilders.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public class StringBuilders {
private StringBuilder sbLatin2;
private StringBuilder sbUtf16;
private StringBuilder sbUtf17;
private int[] intsArray;
private long[] longArray;

@Setup
public void setup() {
Expand All @@ -69,6 +71,13 @@ public void setup() {
sbLatin2 = new StringBuilder("Latin1 string");
sbUtf16 = new StringBuilder("UTF-\uFF11\uFF16 string");
sbUtf17 = new StringBuilder("UTF-\uFF11\uFF16 string");
int size = 16;
intsArray = new int[size];
longArray = new long[size];
for (int i = 0; i < longArray.length; i++) {
intsArray[i] = ((100 * i + i) << 24) + 4543 + i * 4;
longArray[i] = ((100L * i + i) << 32) + 4543 + i * 4L;
}
}

@Benchmark
Expand Down Expand Up @@ -224,6 +233,47 @@ public String toStringCharWithInt8() {
return result.toString();
}

@Benchmark
public int appendWithIntLatin1() {
StringBuilder buf = sbLatin1;
buf.setLength(0);
for (long l : longArray) {
buf.append(l);
}
return buf.length();
}

@Benchmark
public int appendWithIntUtf16() {
StringBuilder buf = sbUtf16;
buf.setLength(0);
buf.setLength(0);
for (long l : longArray) {
buf.append(l);
}
return buf.length();
}

@Benchmark
public int appendWithLongLatin1() {
StringBuilder buf = sbLatin1;
buf.setLength(0);
for (long l : longArray) {
buf.append(l);
}
return buf.length();
}

@Benchmark
public int appendWithLongUtf16() {
StringBuilder buf = sbUtf16;
buf.setLength(0);
buf.setLength(0);
for (long l : longArray) {
buf.append(l);
}
return buf.length();
}

@Benchmark
public int appendWithBool8Latin1() {
Expand Down