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: get rid of forEach() and slice() in IPC
  • Loading branch information
ypresto committed Dec 31, 2016
commit ccac4b46c87b630bbef5608a1c7d465d259f473c
14 changes: 7 additions & 7 deletions lib/internal/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,19 +447,19 @@ function setupChannel(target, channel) {
// TODO(bnoordhuis) Check that nread > 0.
if (pool) {
// Linebreak is used as a message end sign
var lines = decoder.write(pool).split('\n');
var chunks = lines.slice(0, -1);
var chunks = decoder.write(pool).split('\n');
var numCompleteChunks = chunks.length - 1;
// Last line does not have trailing linebreak
var incompleteChunk = lines[lines.length - 1];
if (chunks.length === 0) {
var incompleteChunk = chunks[numCompleteChunks];
if (numCompleteChunks === 0) {
jsonBuffer += incompleteChunk;
this.buffering = jsonBuffer.length !== 0;
return;
}
chunks[0] = jsonBuffer + chunks[0];

chunks.forEach(function(json) {
var message = JSON.parse(json);
for (var i = 0; i < numCompleteChunks; i++) {
var message = JSON.parse(chunks[i]);

// There will be at most one NODE_HANDLE message in every chunk we
// read because SCM_RIGHTS messages don't get coalesced. Make sure
Expand All @@ -468,7 +468,7 @@ function setupChannel(target, channel) {
handleMessage(target, message, recvHandle);
else
handleMessage(target, message, undefined);
});
}
jsonBuffer = incompleteChunk;
this.buffering = jsonBuffer.length !== 0;

Expand Down