Skip to content

Commit

Permalink
child_process: get rid of forEach() and slice() in IPC
Browse files Browse the repository at this point in the history
  • Loading branch information
ypresto committed Dec 31, 2016
1 parent 4b13964 commit ccac4b4
Showing 1 changed file with 7 additions and 7 deletions.
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

0 comments on commit ccac4b4

Please sign in to comment.