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

Unified Diff: src/array.js

Issue 851008: Optimized Array.prototype.{lastIndexOf,indexOf} by special casing comparison to undefined. (Closed)
Patch Set: Created 10 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: src/array.js
diff --git a/src/array.js b/src/array.js
index e2aa4ad116724922d55dc7b9ffa129b967f23596..9cb6b6fdb31d03a624a626da232e822ae16f914d 100644
--- a/src/array.js
+++ b/src/array.js
@@ -994,11 +994,16 @@ function ArrayIndexOf(element, index) {
// If index is still negative, search the entire array.
if (index < 0) index = 0;
}
+ if (!IS_UNDEFINED(element)) {
+ for (var i = index; i < length; i++) {
+ if (this[i] === element) return i;
+ }
+ return -1;
+ }
// Lookup through the array.
for (var i = index; i < length; i++) {
- var current = this[i];
- if (!IS_UNDEFINED(current) || i in this) {
- if (current === element) return i;
+ if (IS_UNDEFINED(this[i]) && i in this) {
+ return i;
}
}
return -1;
@@ -1018,10 +1023,15 @@ function ArrayLastIndexOf(element, index) {
else if (index >= length) index = length - 1;
}
// Lookup through the array.
+ if (!IS_UNDEFINED(element)) {
+ for (var i = index; i >= 0; i--) {
+ if (this[i] === element) return i;
+ }
+ return -1;
+ }
for (var i = index; i >= 0; i--) {
- var current = this[i];
- if (!IS_UNDEFINED(current) || i in this) {
- if (current === element) return i;
+ if (IS_UNDEFINED(this[i]) && i in this) {
+ return i;
}
}
return -1;
« 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