Skip to content

Commit

Permalink
use bulk copy methods to initialize writable text and data defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
dwrensha committed Oct 23, 2024
1 parent cfea947 commit b2f7242
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions runtime/src/main/java/org/capnproto/WireHelpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -802,10 +802,12 @@ static Text.Builder getWritableTextPointer(int refOffset,
return new Text.Builder();
} else {
Text.Builder builder = initTextPointer(refOffset, segment, defaultSize);
// TODO is there a way to do this with bulk methods?
for (int i = 0; i < builder.size; ++i) {
builder.buffer.put(builder.offset + i, defaultBuffer.get(defaultOffset * 8 + i));
}

ByteBuffer slice = defaultBuffer.duplicate();
slice.position(defaultOffset * 8);
slice.limit(defaultOffset * 8 + defaultSize);
builder.buffer.position(builder.offset);
builder.buffer.put(slice);
return builder;
}
}
Expand Down Expand Up @@ -872,10 +874,12 @@ static Data.Builder getWritableDataPointer(int refOffset,
return new Data.Builder();
} else {
Data.Builder builder = initDataPointer(refOffset, segment, defaultSize);
// TODO is there a way to do this with bulk methods?
for (int i = 0; i < builder.size; ++i) {
builder.buffer.put(builder.offset + i, defaultBuffer.get(defaultOffset * 8 + i));
}

ByteBuffer slice = defaultBuffer.duplicate();
slice.position(defaultOffset * 8);
slice.limit(defaultOffset * 8 + defaultSize);
builder.buffer.position(builder.offset);
builder.buffer.put(slice);
return builder;
}
}
Expand Down

0 comments on commit b2f7242

Please sign in to comment.