child_process: fix O(n*m) scan of cmd string

Don't scan the whole string for a "NODE_" substring, just check that
the string starts with the expected prefix.

This is a reprise of dbbfbe7 but this time for the child_process
module.
This commit is contained in:
Ben Noordhuis 2013-04-11 13:50:45 +02:00
parent dbbfbe74ca
commit 212eb8a52e

View File

@ -305,19 +305,17 @@ function getSocketList(type, slave, key) {
return socketList;
}
var INTERNAL_PREFIX = 'NODE_';
function handleMessage(target, message, handle) {
//Filter out internal messages
//if cmd property begin with "_NODE"
var eventName = 'message';
if (message !== null &&
typeof message === 'object' &&
typeof message.cmd === 'string' &&
message.cmd.indexOf('NODE_') === 0) {
target.emit('internalMessage', message, handle);
}
//Non-internal message
else {
target.emit('message', message, handle);
message.cmd.length > INTERNAL_PREFIX.length &&
message.cmd.slice(0, INTERNAL_PREFIX.length) === INTERNAL_PREFIX) {
eventName = 'internalMessage';
}
target.emit(eventName, message, handle);
}
function setupChannel(target, channel) {