Skip to content

Commit

Permalink
Avoid buffer copies during writes.
Browse files Browse the repository at this point in the history
Signed-off-by: Santiago Pericasgeertsen <[email protected]>
  • Loading branch information
spericas committed Jan 10, 2024
1 parent afa735d commit 7eb69f4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Oracle and/or its affiliates.
* Copyright (c) 2022, 2024 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -38,7 +38,17 @@ public BufferData rewind() {

@Override
public void writeTo(OutputStream out) {
copy().writeTo(out);
for (BufferData datum : data) {
if (datum instanceof CompositeBufferData) {
datum.writeTo(out);
} else {
int available = datum.available();
if (available > 0) {
datum.writeTo(out);
datum.skip(-available);
}
}
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Oracle and/or its affiliates.
* Copyright (c) 2022, 2024 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -56,7 +56,17 @@ public BufferData rewind() {

@Override
public void writeTo(OutputStream out) {
copy().writeTo(out);
for (BufferData datum : data) {
if (datum instanceof CompositeBufferData) {
datum.writeTo(out);
} else {
int available = datum.available();
if (available > 0) {
datum.writeTo(out);
datum.skip(-available);
}
}
}
}

@Override
Expand Down

0 comments on commit 7eb69f4

Please sign in to comment.