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:
parent
dbbfbe74ca
commit
212eb8a52e
@ -305,19 +305,17 @@ function getSocketList(type, slave, key) {
|
|||||||
return socketList;
|
return socketList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var INTERNAL_PREFIX = 'NODE_';
|
||||||
function handleMessage(target, message, handle) {
|
function handleMessage(target, message, handle) {
|
||||||
//Filter out internal messages
|
var eventName = 'message';
|
||||||
//if cmd property begin with "_NODE"
|
|
||||||
if (message !== null &&
|
if (message !== null &&
|
||||||
typeof message === 'object' &&
|
typeof message === 'object' &&
|
||||||
typeof message.cmd === 'string' &&
|
typeof message.cmd === 'string' &&
|
||||||
message.cmd.indexOf('NODE_') === 0) {
|
message.cmd.length > INTERNAL_PREFIX.length &&
|
||||||
target.emit('internalMessage', message, handle);
|
message.cmd.slice(0, INTERNAL_PREFIX.length) === INTERNAL_PREFIX) {
|
||||||
}
|
eventName = 'internalMessage';
|
||||||
//Non-internal message
|
|
||||||
else {
|
|
||||||
target.emit('message', message, handle);
|
|
||||||
}
|
}
|
||||||
|
target.emit(eventName, message, handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupChannel(target, channel) {
|
function setupChannel(target, channel) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user