Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

optimizations

  • Loading branch information...
commit c1210d1a77130964158279a7958d18cb6578aa17 1 parent 433e06c
Elijah Insua authored April 13, 2012
6  examples/hello-http.js
@@ -21,8 +21,10 @@ var conductor = require("../lib/conductor").conductor,
21 21
                 }, "listener"),
22 22
 
23 23
     // Create a node to handle the incoming request (routing/etc)
24  
-    handler   = flow.node(function(request) { 
25  
-                  return "hello world!\n"
  24
+    index     = 0,
  25
+    handler   = flow.node(function(request) {
  26
+                  index++;
  27
+                  return 'hello world! #' + index + '\n'
26 28
                 }, "handler"),
27 29
 
28 30
     // Create a node that will respond to the request
36  lib/conductor.js
@@ -180,17 +180,6 @@ OTHER DEALINGS IN THE SOFTWARE.
180 180
   Edge.prototype = {
181 181
     length : 0,
182 182
 
183  
-    // Getter for the current number of ports in this edge
184  
-    /*length : function () {
185  
-      var l = 0, p;
186  
-      for (p in this.ports) {
187  
-        if (this.ports.hasOwnProperty(p)) {
188  
-          l++;
189  
-        }
190  
-      }
191  
-      return l;
192  
-    },*/
193  
-
194 183
     // Mark satisfaction in the current Context, and attempt to trigger this edge
195 184
     satisfy : function (context, port, value) {
196 185
       if (context.emit) {
@@ -253,14 +242,14 @@ OTHER DEALINGS IN THE SOFTWARE.
253 242
 
254 243
         // Forward all the output values
255 244
         for (i in outputPorts) {
256  
-          if (this.node.edges.output.ports.hasOwnProperty(i)) {
  245
+          if (outputPorts.hasOwnProperty(i)) {
257 246
             outputPorts[i].forward(context);
258 247
           }
259 248
         }
260 249
 
261 250
         // Forward all of the callback values
262 251
         for (c in callbackPorts) {
263  
-          if (this.node.edges.callback.ports.hasOwnProperty(c)) {
  252
+          if (callbackPorts.hasOwnProperty(c)) {
264 253
             callbackPorts[c].forward(context);
265 254
           }
266 255
         }
@@ -621,20 +610,21 @@ OTHER DEALINGS IN THE SOFTWARE.
621 610
     // Attempt to find a match between the incoming context and any one of the queue entries' contexts
622 611
     this.match = function (context) {
623 612
       if (context.emit) { context.emit("port.match.start", { port: this, context: context }); }
624  
-      var i, c;
625  
-      for (i = 0; i < this.queue.length; i++) {
  613
+      var i, c, currentQueueItem = this.queue.length, currentFork;
  614
+      while (currentQueueItem--) {
626 615
 
627 616
         // If the incoming context is the same as the current queue item's context, then we have a match
628  
-        if (this.queue[i].context === context) {
629  
-          if (context.emit) { context.emit("port.match.end", { port: this, context: context, result: i }); }
630  
-          return i;
  617
+        if (this.queue[currentQueueItem].context === context) {
  618
+          if (context.emit) { context.emit("port.match.end", { port: this, context: context, result: currentQueueItem }); }
  619
+          return currentQueueItem;
631 620
         }
632 621
 
633 622
         // Attempt to match the queue items against the current context's fork queue
634  
-        for (c = 0; c < this.queue[i].context.forks.length; c++) {
  623
+        currentFork = this.queue[currentQueueItem].context.forks.length;
  624
+        while(currentFork--) {
635 625
           // Does this queue context and the current context have a common fork context ancestor?
636  
-          if (context.forks.indexOf(this.queue[i].context.forks[c]) !== -1) {
637  
-            if (context.emit) { context.emit("port.match.end", { port: this, context: context, result: i }); }
  626
+          if (context.forks.indexOf(this.queue[currentQueueItem].context.forks[currentFork]) !== -1) {
  627
+            if (context.emit) { context.emit("port.match.end", { port: this, context: context, result: currentQueueItem }); }
638 628
             return i;
639 629
           }
640 630
         }
@@ -657,9 +647,9 @@ OTHER DEALINGS IN THE SOFTWARE.
657 647
     // This is done by satisfying all of the target port's with the value.
658 648
     this.forward = function (context) {
659 649
       if (context.emit) { context.emit("port.forward.start", { port: this, context: context }); }
660  
-      var forwarded = {}, p, target, targetStr;
  650
+      var forwarded = {}, p = this.pipes.length, target, targetStr;
661 651
       // Satisfy the downstream ports
662  
-      for (p = 0; p < this.pipes.length; p++) {
  652
+      while(p--) {
663 653
         target       = this.pipes[p];
664 654
         targetStr    = target.edge.node.index + "@" +
665 655
                            target.edge.type + "#" + target.index;

0 notes on commit c1210d1

Please sign in to comment.
Something went wrong with that request. Please try again.