aboutsummaryrefslogtreecommitdiff
path: root/src/enzymatic.js
diff options
context:
space:
mode:
authoralon@honor <none@none>2010-08-30 21:30:09 -0700
committeralon@honor <none@none>2010-08-30 21:30:09 -0700
commit50a1abf1ad3260d63f0ed0b3558e739ce5eb1f41 (patch)
tree1f491538b2388fd9a54bf773bed34b431f8dc42d /src/enzymatic.js
parent100294df68fd63c1a80b81264cb98d772e7e09fc (diff)
imported patch optimize_enzymatic
Diffstat (limited to 'src/enzymatic.js')
-rw-r--r--src/enzymatic.js44
1 files changed, 38 insertions, 6 deletions
diff --git a/src/enzymatic.js b/src/enzymatic.js
index ea6a4f27..41fa6e81 100644
--- a/src/enzymatic.js
+++ b/src/enzymatic.js
@@ -22,6 +22,12 @@ Substrate.prototype = {
},
addZyme: function(zyme) {
+ var name_ = '?';
+ if (typeof zyme == 'string') {
+ name_ = zyme;
+ zyme = arguments[1];
+ }
+ zyme.name_ = name_;
this.zymes.push(zyme);
if (!zyme.select) zyme.select = Zyme.prototype.select;
if (!zyme.process) zyme.process = Zyme.prototype.process;
@@ -48,9 +54,10 @@ Substrate.prototype = {
// Assumes list of Zymes is non-changing.
var results = [];
while (true) {
- if (DEBUG) print("Cycle start, " + this.items.length + " items.");
+ dprint('enzymatic', "Cycle start, " + this.items.length + " items.");
var hadProcessing = false;
for (var z = 0; z < this.zymes.length; z++) {
+ midComment();
var zyme = this.zymes[z];
var selected = zyme.select(this.items);
if (selected.length > 0) {
@@ -63,10 +70,13 @@ Substrate.prototype = {
}
}
hadProcessing = true;
- this.items = this.items.filter(function(item) { return selected.indexOf(item) == -1 });
var outputs;
try {
+ dprint('Processing using ' + zyme.name_);
+ PROF(true);
outputs = zyme.process(selected);
+ PROF();
+ dprint('...complete');
} catch (e) {
print("Exception, current selected are: " + selected.map(dump).join('\n\n').substr(0,100));
print("Stack: " + new Error().stack);
@@ -87,16 +97,38 @@ Substrate.prototype = {
return outputs[0];
}
results = results.concat(outputs.filter(function(output) { return !!output.__result__; }))
+/*
+ this.items = this.items.filter(function(item) { PROF(); return selected.indexOf(item) == -1 });
outputs.filter(function(output) { return !output.__result__; }).forEach(this.addItem, this);
- results.forEach(function(output) {
- delete output.__result__; // Might recycle these
- delete output.__uid__;
- });
+*/
+ var nonResults = outputs.filter(function(output) { return !output.__result__; });
+
+ var keptUids = {};
+ nonResults.forEach(function(s) {
+ if (s.__uid__) {
+ keptUids[s.__uid__] = true;
+ } else {
+ this.addItem(s);
+ }
+ }, this);
+ var droppedUids = {};
+ selected.forEach(function(s) { if (!keptUids[s.__uid__]) droppedUids[s.__uid__] = true });
+ this.items = this.items.filter(function(item) {
+ if (!droppedUids[item.__uid__]) {
+ return true;
+ } else {
+ delete item.__uid__;
+ }
+ });
}
}
if (this.items.length === 0) {
if (DEBUG) print("Solving complete: no remaining items");
finalComment();
+ results.forEach(function(output) {
+ delete output.__result__; // Might recycle these
+ delete output.__uid__;
+ });
return results;
}
if (!hadProcessing) {