Skip to content

Commit 003108f

Browse files
committed
StreamEncoder provides CharBuffer fast-path in append
1 parent 8da8f55 commit 003108f

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

src/java.base/share/classes/java/io/OutputStreamWriter.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,7 @@ public Writer append(CharSequence csq, int start, int end) throws IOException {
232232

233233
@Override
234234
public Writer append(CharSequence csq) throws IOException {
235-
if (csq instanceof CharBuffer) {
236-
se.write((CharBuffer) csq);
237-
} else {
238-
se.append(csq);
239-
}
235+
se.append(csq);
240236
return this;
241237
}
242238

src/java.base/share/classes/sun/nio/cs/StreamEncoder.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,22 @@ public void write(CharBuffer cb) throws IOException {
151151
}
152152

153153
public Writer append(CharSequence csq) throws IOException {
154-
if (csq == null) csq = "null";
155-
implWrite(csq, 0, csq.length());
154+
if (csq instanceof CharBuffer cb) {
155+
write(cb);
156+
} else {
157+
if (csq == null) csq = "null";
158+
implWrite(csq, 0, csq.length());
159+
}
156160
return this;
157161
}
158162

159163
public Writer append(CharSequence csq, int start, int end) throws IOException {
160-
if (csq == null) csq = "null";
161-
implWrite(csq, start, end - start);
164+
if (csq instanceof CharBuffer cb) {
165+
write(cb.subSequence(start, end));
166+
} else {
167+
if (csq == null) csq = "null";
168+
implWrite(csq, start, end - start);
169+
}
162170
return this;
163171
}
164172

0 commit comments

Comments
 (0)