Skip to content

Commit

Permalink
allegro#21 do not concat buffers when not on Windows (perf)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhharker committed Aug 28, 2018
1 parent 14f69a1 commit 5934ed3
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions lib/worker/transport.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const os = require("os");
const EventEmitter = require('events');
const msgpack = require("msgpack-lite");

Expand Down Expand Up @@ -55,14 +56,20 @@ class Transport extends EventEmitter {
const payloadLength = serializedMessage.byteLength;

const header = new Uint32Array([payloadLength]);
const headerLength = Uint32Array.BYTES_PER_ELEMENT * header.length;

this.pipe.write(
Buffer.concat(
[Buffer.from(header.buffer), serializedMessage],
payloadLength + headerLength
)
);

if (os.platform() === "win32") {
const headerLength = Uint32Array.BYTES_PER_ELEMENT * header.length;
this.pipe.write(
Buffer.concat(
[Buffer.from(header.buffer), serializedMessage],
payloadLength + headerLength
)
);
}
else {
this.pipe.write(Buffer.from(header.buffer));
this.pipe.write(serializedMessage);
}
}
}

Expand Down

0 comments on commit 5934ed3

Please sign in to comment.