Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
child_process: add the suggestion from @BridgeAR
  • Loading branch information
CaramelFur committed Jun 15, 2022
commit ff29aeca7caa8d129402be9faeb80938e2f4e537
14 changes: 5 additions & 9 deletions lib/internal/child_process/serialization.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,11 @@ const advanced = {
// Index 0 should always be present because we just pushed data into it.
let messageBufferHead = channel[kMessageBuffer][0];
while (messageBufferHead.length >= 4) {
// We read the uint manually here, because this is faster than first converting
// We call `readUInt32BE` manually here, because this is faster than first converting
// it to a buffer and using `readUInt32BE` on that.
const size =
messageBufferHead[0] << 24 |
messageBufferHead[1] << 16 |
messageBufferHead[2] << 8 |
messageBufferHead[3];
const fullMessageSize = Buffer.prototype.readUInt32BE.call(messageBufferHead, 0) + 4;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const { readUInt32BE } = require('internal/buffer');
// ...
const fullMessageSize = ReflectApply(readUInt32BE, messageBufferHead, [0]) + 4;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change has been added


if (channel[kMessageBufferSize] < 4 + size) break;
if (channel[kMessageBufferSize] < fullMessageSize) break;

const concatenatedBuffer = channel[kMessageBuffer].length === 1 ?
Comment thread
targos marked this conversation as resolved.
channel[kMessageBuffer][0] :
Expand All @@ -84,10 +80,10 @@ const advanced = {
);

const deserializer = new ChildProcessDeserializer(
TypedArrayPrototypeSubarray(concatenatedBuffer, 4, 4 + size)
TypedArrayPrototypeSubarray(concatenatedBuffer, 4, fullMessageSize)
);

messageBufferHead = TypedArrayPrototypeSubarray(concatenatedBuffer, 4 + size);
messageBufferHead = TypedArrayPrototypeSubarray(concatenatedBuffer, fullMessageSize);
channel[kMessageBufferSize] = messageBufferHead.length;
channel[kMessageBuffer] =
channel[kMessageBufferSize] !== 0 ? [messageBufferHead] : [];
Expand Down