8357286: (bf) Remove obsolete instanceof checks in CharBuffer.append
Reviewed-by: alanb
This commit is contained in:
parent
66535fe26d
commit
0dd7c69b9e
@ -430,8 +430,13 @@ class Direct$Type$Buffer$RW$$BO$
|
|||||||
|
|
||||||
#if[rw]
|
#if[rw]
|
||||||
private static final int APPEND_BUF_SIZE = 1024;
|
private static final int APPEND_BUF_SIZE = 1024;
|
||||||
|
#end[rw]
|
||||||
|
|
||||||
|
public $Type$Buffer append(CharSequence csq, int start, int end) {
|
||||||
|
#if[rw]
|
||||||
|
if (csq == null)
|
||||||
|
return super.append(csq, start, end);
|
||||||
|
|
||||||
private $Type$Buffer appendChars(CharSequence csq, int start, int end) {
|
|
||||||
Objects.checkFromToIndex(start, end, csq.length());
|
Objects.checkFromToIndex(start, end, csq.length());
|
||||||
|
|
||||||
int pos = position();
|
int pos = position();
|
||||||
@ -448,13 +453,7 @@ class Direct$Type$Buffer$RW$$BO$
|
|||||||
if (count > buf.length)
|
if (count > buf.length)
|
||||||
count = buf.length;
|
count = buf.length;
|
||||||
|
|
||||||
if (csq instanceof String str) {
|
csq.getChars(start, start + count, buf, 0);
|
||||||
str.getChars(start, start + count, buf, 0);
|
|
||||||
} else if (csq instanceof StringBuilder sb) {
|
|
||||||
sb.getChars(start, start + count, buf, 0);
|
|
||||||
} else if (csq instanceof StringBuffer sb) {
|
|
||||||
sb.getChars(start, start + count, buf, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
putArray(index, buf, 0, count);
|
putArray(index, buf, 0, count);
|
||||||
|
|
||||||
@ -465,27 +464,19 @@ class Direct$Type$Buffer$RW$$BO$
|
|||||||
position(pos + length);
|
position(pos + length);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
|
||||||
#end[rw]
|
|
||||||
|
|
||||||
public $Type$Buffer append(CharSequence csq) {
|
|
||||||
#if[rw]
|
|
||||||
if (csq instanceof StringBuilder)
|
|
||||||
return appendChars(csq, 0, csq.length());
|
|
||||||
|
|
||||||
return super.append(csq);
|
|
||||||
#else[rw]
|
#else[rw]
|
||||||
throw new ReadOnlyBufferException();
|
throw new ReadOnlyBufferException();
|
||||||
#end[rw]
|
#end[rw]
|
||||||
}
|
}
|
||||||
|
|
||||||
public $Type$Buffer append(CharSequence csq, int start, int end) {
|
|
||||||
#if[rw]
|
|
||||||
if (csq instanceof String || csq instanceof StringBuffer ||
|
|
||||||
csq instanceof StringBuilder)
|
|
||||||
return appendChars(csq, start, end);
|
|
||||||
|
|
||||||
return super.append(csq, start, end);
|
public $Type$Buffer append(CharSequence csq) {
|
||||||
|
#if[rw]
|
||||||
|
// See comment regarding StringBuilder on HeapBuffer.append.
|
||||||
|
if (csq instanceof StringBuilder)
|
||||||
|
return append(csq, 0, csq.length());
|
||||||
|
|
||||||
|
return super.append(csq);
|
||||||
#else[rw]
|
#else[rw]
|
||||||
throw new ReadOnlyBufferException();
|
throw new ReadOnlyBufferException();
|
||||||
#end[rw]
|
#end[rw]
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2000, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -290,7 +290,11 @@ class Heap$Type$Buffer$RW$
|
|||||||
// or the full sequence of chars is being appended, copying the chars to
|
// or the full sequence of chars is being appended, copying the chars to
|
||||||
// an intermedite String in StringBuilder::toString is avoided.
|
// an intermedite String in StringBuilder::toString is avoided.
|
||||||
//
|
//
|
||||||
private $Type$Buffer appendChars(CharSequence csq, int start, int end) {
|
public $Type$Buffer append(CharSequence csq, int start, int end) {
|
||||||
|
#if[rw]
|
||||||
|
if (csq == null)
|
||||||
|
return super.append(csq, start, end);
|
||||||
|
|
||||||
checkSession();
|
checkSession();
|
||||||
|
|
||||||
Objects.checkFromToIndex(start, end, csq.length());
|
Objects.checkFromToIndex(start, end, csq.length());
|
||||||
@ -302,37 +306,23 @@ class Heap$Type$Buffer$RW$
|
|||||||
if (length > rem)
|
if (length > rem)
|
||||||
throw new BufferOverflowException();
|
throw new BufferOverflowException();
|
||||||
|
|
||||||
if (csq instanceof String str) {
|
csq.getChars(start, end, hb, ix(pos));
|
||||||
str.getChars(start, end, hb, ix(pos));
|
|
||||||
} else if (csq instanceof StringBuilder sb) {
|
|
||||||
sb.getChars(start, end, hb, ix(pos));
|
|
||||||
} else if (csq instanceof StringBuffer sb) {
|
|
||||||
sb.getChars(start, end, hb, ix(pos));
|
|
||||||
}
|
|
||||||
|
|
||||||
position(pos + length);
|
position(pos + length);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
|
||||||
|
|
||||||
public $Type$Buffer append(CharSequence csq) {
|
|
||||||
#if[rw]
|
|
||||||
if (csq instanceof StringBuilder)
|
|
||||||
return appendChars(csq, 0, csq.length());
|
|
||||||
|
|
||||||
return super.append(csq);
|
|
||||||
#else[rw]
|
#else[rw]
|
||||||
throw new ReadOnlyBufferException();
|
throw new ReadOnlyBufferException();
|
||||||
#end[rw]
|
#end[rw]
|
||||||
}
|
}
|
||||||
|
|
||||||
public $Type$Buffer append(CharSequence csq, int start, int end) {
|
public $Type$Buffer append(CharSequence csq) {
|
||||||
#if[rw]
|
#if[rw]
|
||||||
if (csq instanceof String || csq instanceof StringBuffer ||
|
// See comment regarding StringBuilder on method append() above.
|
||||||
csq instanceof StringBuilder)
|
if (csq instanceof StringBuilder)
|
||||||
return appendChars(csq, start, end);
|
return append(csq, 0, csq.length());
|
||||||
|
|
||||||
return super.append(csq, start, end);
|
return super.append(csq);
|
||||||
#else[rw]
|
#else[rw]
|
||||||
throw new ReadOnlyBufferException();
|
throw new ReadOnlyBufferException();
|
||||||
#end[rw]
|
#end[rw]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user