Skip to content
Merged
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
14 changes: 9 additions & 5 deletions java/src/json/ext/SWARBasicStringEncoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ void encode(ByteList src) throws IOException {
int beg = 0;
int pos = 0;

ByteBuffer bb = ByteBuffer.wrap(ptrBytes, 0, len);
while (ptr + pos + 8 <= len) {
long x = bb.getLong(ptr + pos);
// There are optimizations in JRuby where ptr > 0 will be true. For example, if we
// slice a string, the underlying byte array is the same, but the
// begin index and real size are different. When reading from the ptrBytes
// array, we need to always add ptr to the index.
ByteBuffer bb = ByteBuffer.wrap(ptrBytes, ptr, len);
while (pos + 8 <= len) {
long x = bb.getLong(pos);
if (skipChunk(x)) {
pos += 8;
continue;
Expand All @@ -43,8 +47,8 @@ void encode(ByteList src) throws IOException {
}
}

if (ptr + pos + 4 <= len) {
int x = bb.getInt(ptr + pos);
if (pos + 4 <= len) {
int x = bb.getInt(pos);
if (skipChunk(x)) {
pos += 4;
}
Expand Down
Loading