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

Unified Diff: Source/devtools/front_end/utilities.js

Issue 212863005: DevTools: Make Array.remove O(N). (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 9 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/devtools/front_end/utilities.js
diff --git a/Source/devtools/front_end/utilities.js b/Source/devtools/front_end/utilities.js
index bd98244bd26729eb527f1aa6795b0a2a6a4da7af..74616b5f1404ee93e9dec708913f7972c86bec3a 100644
--- a/Source/devtools/front_end/utilities.js
+++ b/Source/devtools/front_end/utilities.js
@@ -380,17 +380,18 @@ Object.defineProperty(Array.prototype, "remove",
*/
value: function(value, firstOnly)
{
+ var index = this.indexOf(value);
+ if (index === -1)
+ return;
if (firstOnly) {
- var index = this.indexOf(value);
- if (index !== -1)
- this.splice(index, 1);
+ this.splice(index, 1);
return;
}
-
- for (var i = 0; i < this.length; ++i) {
- if (this[i] === value)
- this.splice(i--, 1);
+ for (var i = index + 1, n = this.length; i < n; ++i) {
+ if (this[i] !== value)
+ this[index++] = this[i];
}
+ this.length = index;
}
});
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698