| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1491,6 +1491,37 @@ public void readPayload(ByteBuffer dst) | |||
| 1491 | 1491 | } | |
| 1492 | 1492 | } | |
| 1493 | 1493 | ||
| 1494 | + /** | ||
| 1495 | + * Reads payload bytes of binary, extension, or raw string types. | ||
| 1496 | + * | ||
| 1497 | + * <p> | ||
| 1498 | + * This consumes bytes, copies them to the specified buffer | ||
| 1499 | + * This is usually faster than readPayload(ByteBuffer) by using unsafe.copyMemory | ||
| 1500 | + * | ||
| 1501 | + * @param dst the Message buffer into which the data is read | ||
| 1502 | + * @param off the offset in the Message buffer | ||
| 1503 | + * @param len the number of bytes to read | ||
| 1504 | + * @throws IOException when underlying input throws IOException | ||
| 1505 | + */ | ||
| 1506 | + public void readPayload(MessageBuffer dst, int off, int len) | ||
| 1507 | + throws IOException | ||
| 1508 | + { | ||
| 1509 | + while (true) { | ||
| 1510 | + int bufferRemaining = buffer.size() - position; | ||
| 1511 | + if (bufferRemaining >= len) { | ||
| 1512 | + dst.putMessageBuffer(off, buffer, position, len); | ||
| 1513 | + position += len; | ||
| 1514 | + return; | ||
| 1515 | + } | ||
| 1516 | + dst.putMessageBuffer(off, buffer, position, bufferRemaining); | ||
| 1517 | + off += bufferRemaining; | ||
| 1518 | + len -= bufferRemaining; | ||
| 1519 | + position += bufferRemaining; | ||
| 1520 | + | ||
| 1521 | + nextBuffer(); | ||
| 1522 | + } | ||
| 1523 | + } | ||
| 1524 | + | ||
| 1494 | 1525 | /** | |
| 1495 | 1526 | * Reads payload bytes of binary, extension, or raw string types. | |
| 1496 | 1527 | * | |
@@ -1541,8 +1572,7 @@ public byte[] readPayload(int length) | |||
| 1541 | 1572 | public void readPayload(byte[] dst, int off, int len) | |
| 1542 | 1573 | throws IOException | |
| 1543 | 1574 | { | |
| 1544 | - // TODO optimize | ||
| 1545 | - readPayload(ByteBuffer.wrap(dst, off, len)); | ||
| 1575 | + readPayload(MessageBuffer.wrap(dst), off, len); | ||
| 1546 | 1576 | } | |
| 1547 | 1577 | ||
| 1548 | 1578 | /** | |
@@ -1566,7 +1596,7 @@ public MessageBuffer readPayloadAsReference(int length) | |||
| 1566 | 1596 | return slice; | |
| 1567 | 1597 | } | |
| 1568 | 1598 | MessageBuffer dst = MessageBuffer.allocate(length); | |
| 1569 | - readPayload(dst.sliceAsByteBuffer()); | ||
| 1599 | + readPayload(dst, 0, length); | ||
| 1570 | 1600 | return dst; | |
| 1571 | 1601 | } | |
| 1572 | 1602 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -248,7 +248,7 @@ public void copyTo(int index, MessageBuffer dst, int offset, int length) | |||
| 248 | 248 | @Override | |
| 249 | 249 | public void putMessageBuffer(int index, MessageBuffer src, int srcOffset, int len) | |
| 250 | 250 | { | |
| 251 | - putBytes(index, src.toByteArray(), srcOffset, len); | ||
| 251 | + putByteBuffer(index, src.sliceAsByteBuffer(srcOffset, len), len); | ||
| 252 | 252 | } | |
| 253 | 253 | ||
| 254 | 254 | @Override | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -406,7 +406,7 @@ class MessageUnpackerTest extends MessagePackSpec { | |||
| 406 | 406 | } | |
| 407 | 407 | } | |
| 408 | 408 | ||
| 409 | - "be faster then msgpack-v6 skip" taggedAs ("cmp-skip") in { | ||
| 409 | + "be faster than msgpack-v6 skip" taggedAs ("cmp-skip") in { | ||
| 410 | 410 | ||
| 411 | 411 | trait Fixture { | |
| 412 | 412 | val unpacker: MessageUnpacker | |
| Back | FazBrowse Home | New Git URL |
0 commit comments