summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2013-04-11 13:18:02 +0200
committerBen Noordhuis <info@bnoordhuis.nl>2013-04-11 13:42:34 +0200
commitdbbfbe74caa8d5e76d32222735766435682b2b94 (patch)
tree94f3db434f19163f59e488b483c5f0d75b61aff2 /lib
parentcd96f0aba8fcec2be2274ff56af767c1f16e7f50 (diff)
downloadandroid-node-v8-dbbfbe74caa8d5e76d32222735766435682b2b94.tar.gz
android-node-v8-dbbfbe74caa8d5e76d32222735766435682b2b94.tar.bz2
android-node-v8-dbbfbe74caa8d5e76d32222735766435682b2b94.zip
cluster: fix O(n*m) scan of cmd string
Don't scan the whole string for a "NODE_CLUSTER_" substring, just check that the string starts with the expected prefix. The linear scan was causing a noticeable (but unsurprising) slowdown on messages with a large .cmd string property.
Diffstat (limited to 'lib')
-rw-r--r--lib/cluster.js5
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/cluster.js b/lib/cluster.js
index 5561c9fbcf..5245ab02a4 100644
--- a/lib/cluster.js
+++ b/lib/cluster.js
@@ -141,9 +141,10 @@ cluster.setupMaster = function(options) {
// Check if a message is internal only
var INTERNAL_PREFIX = 'NODE_CLUSTER_';
function isInternalMessage(message) {
- return (isObject(message) &&
+ return isObject(message) &&
typeof message.cmd === 'string' &&
- message.cmd.indexOf(INTERNAL_PREFIX) === 0);
+ message.cmd.length > INTERNAL_PREFIX.length &&
+ message.cmd.slice(0, INTERNAL_PREFIX.length) === INTERNAL_PREFIX;
}
// Modify message object to be internal