Skip to content

Commit ccac4b4

Browse files
committedDec 31, 2016
child_process: get rid of forEach() and slice() in IPC
1 parent 4b13964 commit ccac4b4

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed
 

‎lib/internal/child_process.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -447,19 +447,19 @@ function setupChannel(target, channel) {
447447
// TODO(bnoordhuis) Check that nread > 0.
448448
if (pool) {
449449
// Linebreak is used as a message end sign
450-
var lines = decoder.write(pool).split('\n');
451-
var chunks = lines.slice(0, -1);
450+
var chunks = decoder.write(pool).split('\n');
451+
var numCompleteChunks = chunks.length - 1;
452452
// Last line does not have trailing linebreak
453-
var incompleteChunk = lines[lines.length - 1];
454-
if (chunks.length === 0) {
453+
var incompleteChunk = chunks[numCompleteChunks];
454+
if (numCompleteChunks === 0) {
455455
jsonBuffer += incompleteChunk;
456456
this.buffering = jsonBuffer.length !== 0;
457457
return;
458458
}
459459
chunks[0] = jsonBuffer + chunks[0];
460460

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

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

0 commit comments

Comments
 (0)