Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(484)

Unified Diff: tools/turbolizer/util.js

Issue 2050233002: [turbolizer] Add 2 buttons; add middle-click on input; add comment in UI. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@mywork
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/turbolizer/index.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/turbolizer/util.js
diff --git a/tools/turbolizer/util.js b/tools/turbolizer/util.js
index 09a747379018c3c650280f30319567abe425c83a..652f0c6bf2f4fcd8b4a585125d962ab1b3f5d5af 100644
--- a/tools/turbolizer/util.js
+++ b/tools/turbolizer/util.js
@@ -69,3 +69,43 @@ function sortUnique(arr, f) {
}
return ret;
}
+
+// Find elements in the array that match a filter. Apply an action on each
+// such element. Check if new elements match the filter; apply the action to
+// those elements. Repeat until no new elements match the filter and the
+// action has been called at least once on elements that match the filter.
+//
+// The filter should not have any side effects. Any elements that match the
+// filter should continue to match the filter, regardless of calls to the
+// action on arbitrary elements.
+//
+// Returns nothing.
+function filterActionUntilStabilize(arr, filt, action) {
+
+ var elementsLeft = arr.slice(); // shallow copy
+
+ while (true) {
+ var matching = [];
+ var nonMatching = [];
+
+ elementsLeft.forEach(function(element) {
+ if (filt(element)) {
+ matching.push(element);
+ action(element);
+ } else {
+ nonMatching.push(element);
+ }
+ });
+
+ if (elementsLeft.length == nonMatching.length) {
+ // We stabilized; exit.
+ break;
+ } else {
+ // Some elements matched and we called the action. It is possible that
+ // elements that never matched the filter, will match it on the next
+ // iteration.
+ elementsLeft = nonMatching;
+ continue;
+ }
+ }
+}
« no previous file with comments | « tools/turbolizer/index.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698