Browse files

optimizations

  • Loading branch information...
1 parent 433e06c commit c1210d1a77130964158279a7958d18cb6578aa17 @tmpvar committed Apr 13, 2012
Showing with 17 additions and 25 deletions.
  1. +4 −2 examples/hello-http.js
  2. +13 −23 lib/conductor.js
View
6 examples/hello-http.js
@@ -21,8 +21,10 @@ var conductor = require("../lib/conductor").conductor,
}, "listener"),
// Create a node to handle the incoming request (routing/etc)
- handler = flow.node(function(request) {
- return "hello world!\n"
+ index = 0,
+ handler = flow.node(function(request) {
+ index++;
+ return 'hello world! #' + index + '\n'
}, "handler"),
// Create a node that will respond to the request
View
36 lib/conductor.js
@@ -180,17 +180,6 @@ OTHER DEALINGS IN THE SOFTWARE.
Edge.prototype = {
length : 0,
- // Getter for the current number of ports in this edge
- /*length : function () {
- var l = 0, p;
- for (p in this.ports) {
- if (this.ports.hasOwnProperty(p)) {
- l++;
- }
- }
- return l;
- },*/
-
// Mark satisfaction in the current Context, and attempt to trigger this edge
satisfy : function (context, port, value) {
if (context.emit) {
@@ -253,14 +242,14 @@ OTHER DEALINGS IN THE SOFTWARE.
// Forward all the output values
for (i in outputPorts) {
- if (this.node.edges.output.ports.hasOwnProperty(i)) {
+ if (outputPorts.hasOwnProperty(i)) {
outputPorts[i].forward(context);
}
}
// Forward all of the callback values
for (c in callbackPorts) {
- if (this.node.edges.callback.ports.hasOwnProperty(c)) {
+ if (callbackPorts.hasOwnProperty(c)) {
callbackPorts[c].forward(context);
}
}
@@ -621,20 +610,21 @@ OTHER DEALINGS IN THE SOFTWARE.
// Attempt to find a match between the incoming context and any one of the queue entries' contexts
this.match = function (context) {
if (context.emit) { context.emit("port.match.start", { port: this, context: context }); }
- var i, c;
- for (i = 0; i < this.queue.length; i++) {
+ var i, c, currentQueueItem = this.queue.length, currentFork;
+ while (currentQueueItem--) {
// If the incoming context is the same as the current queue item's context, then we have a match
- if (this.queue[i].context === context) {
- if (context.emit) { context.emit("port.match.end", { port: this, context: context, result: i }); }
- return i;
+ if (this.queue[currentQueueItem].context === context) {
+ if (context.emit) { context.emit("port.match.end", { port: this, context: context, result: currentQueueItem }); }
+ return currentQueueItem;
}
// Attempt to match the queue items against the current context's fork queue
- for (c = 0; c < this.queue[i].context.forks.length; c++) {
+ currentFork = this.queue[currentQueueItem].context.forks.length;
+ while(currentFork--) {
// Does this queue context and the current context have a common fork context ancestor?
- if (context.forks.indexOf(this.queue[i].context.forks[c]) !== -1) {
- if (context.emit) { context.emit("port.match.end", { port: this, context: context, result: i }); }
+ if (context.forks.indexOf(this.queue[currentQueueItem].context.forks[currentFork]) !== -1) {
+ if (context.emit) { context.emit("port.match.end", { port: this, context: context, result: currentQueueItem }); }
return i;
}
}
@@ -657,9 +647,9 @@ OTHER DEALINGS IN THE SOFTWARE.
// This is done by satisfying all of the target port's with the value.
this.forward = function (context) {
if (context.emit) { context.emit("port.forward.start", { port: this, context: context }); }
- var forwarded = {}, p, target, targetStr;
+ var forwarded = {}, p = this.pipes.length, target, targetStr;
// Satisfy the downstream ports
- for (p = 0; p < this.pipes.length; p++) {
+ while(p--) {
target = this.pipes[p];
targetStr = target.edge.node.index + "@" +
target.edge.type + "#" + target.index;

0 comments on commit c1210d1

Please sign in to comment.