FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Improve readPayload performance by miniway · Pull Request #436 · msgpack/msgpack-java · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .java  (2) .scala  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1491,6 +1491,37 @@ public void readPayload(ByteBuffer dst)
}
}

/**
* Reads payload bytes of binary, extension, or raw string types.
*
* <p>
* This consumes bytes, copies them to the specified buffer
* This is usually faster than readPayload(ByteBuffer) by using unsafe.copyMemory
*
* @param dst the Message buffer into which the data is read
* @param off the offset in the Message buffer
* @param len the number of bytes to read
* @throws IOException when underlying input throws IOException
*/
public void readPayload(MessageBuffer dst, int off, int len)
throws IOException
{
while (true) {
int bufferRemaining = buffer.size() - position;
if (bufferRemaining >= len) {
dst.putMessageBuffer(off, buffer, position, len);
position += len;
return;
}
dst.putMessageBuffer(off, buffer, position, bufferRemaining);
off += bufferRemaining;
len -= bufferRemaining;
position += bufferRemaining;

nextBuffer();
}
}

/**
* Reads payload bytes of binary, extension, or raw string types.
*
Expand Down Expand Up @@ -1541,8 +1572,7 @@ public byte[] readPayload(int length)
public void readPayload(byte[] dst, int off, int len)
throws IOException
{
// TODO optimize
readPayload(ByteBuffer.wrap(dst, off, len));
readPayload(MessageBuffer.wrap(dst), off, len);
}

/**
Expand All @@ -1566,7 +1596,7 @@ public MessageBuffer readPayloadAsReference(int length)
return slice;
}
MessageBuffer dst = MessageBuffer.allocate(length);
readPayload(dst.sliceAsByteBuffer());
readPayload(dst, 0, length);
return dst;
}

Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public void copyTo(int index, MessageBuffer dst, int offset, int length)
@Override
public void putMessageBuffer(int index, MessageBuffer src, int srcOffset, int len)
{
putBytes(index, src.toByteArray(), srcOffset, len);
putByteBuffer(index, src.sliceAsByteBuffer(srcOffset, len), len);
}

@Override
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ class MessageUnpackerTest extends MessagePackSpec {
}
}

"be faster then msgpack-v6 skip" taggedAs ("cmp-skip") in {
"be faster than msgpack-v6 skip" taggedAs ("cmp-skip") in {

trait Fixture {
val unpacker: MessageUnpacker
Expand Down

Back | FazBrowse Home | New Git URL