chaokunyang commented on code in PR #1320:
URL: https://github.com/apache/incubator-fury/pull/1320#discussion_r1444270563
##########
javascript/packages/fury/lib/reader/index.ts:
##########
@@ -186,67 +151,137 @@ export const BinaryReader = (config: Config) => {
return result;
}
- function zigZag(v: number) {
- return (v >> 1) ^ -(v & 1);
- }
-
- function zigZagBigInt(v: bigint) {
- return (v >> 1n) ^ -(v & 1n);
- }
-
function varUInt32() {
- let byte_ = uint8();
- let result = byte_ & 0x7f;
- if ((byte_ & 0x80) != 0) {
- byte_ = uint8();
- result |= (byte_ & 0x7f) << 7;
- if ((byte_ & 0x80) != 0) {
- byte_ = uint8();
- result |= (byte_ & 0x7f) << 14;
- if ((byte_ & 0x80) != 0) {
- byte_ = uint8();
- result |= (byte_ & 0x7f) << 21;
- if ((byte_ & 0x80) != 0) {
- byte_ = uint8();
- result |= (byte_) << 28;
+ // Reduce memory reads as much as possible. Reading a uint32 at once is
far faster than reading four uint8s separately.
+ if (buffer.byteLength - cursor >= 5) {
+ const b1 = uint8();
+ const u32 = dataView.getUint32(cursor, true);
Review Comment:
This can be moved into **`if ((b1 & 0x80) != 0) {`**
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]