Remove indexOf from Enumerable#include because it uses strict equality
Reported by John-David Dalton | June 24th, 2008 @ 05:43 PM | in 1.6.1
Garret Smith pointed out that the use of this.indexOf uses strict equality if its being used on an array. So I have patched the method to remove this usage.
Comments and changes to this ticket
-
John-David Dalton June 25th, 2008 @ 03:13 PM
- no changes were found...
-
John-David Dalton June 25th, 2008 @ 03:13 PM
- → State changed from new to bug
- → Tag changed from to patched
-
Tobie Langel June 27th, 2008 @ 03:09 AM
- → State changed from bug to enhancement
- → Milestone changed from 1.6.0.3 to 1.6.1
- → Tag changed from patched to needs_benchmarks needs_failing_test_case needs_tests patched
Use of indexOf here is for perf reasons. (And yes, this would need real benchmarks.)
Other than that, there's no reason for this to return incorrect results.
-
Juriy Zaytsev June 27th, 2008 @ 04:08 AM
It certainly is weird to perform another loop if "indexOf == -1". Why can't we just return its result if method is present?
-
John-David Dalton June 27th, 2008 @ 04:21 AM
Ya Garrett mentioned that too.
Though now that I look at it.
If it failed the "indexOf" (which could be caused by it not meeting the strict equality), it will be looped again manually and it should pick up the match that way. Was this done by design?
If so and the "indexOf" is more of a performance boost (I can see where this ticket is totally not needed).
-
Juriy Zaytsev June 27th, 2008 @ 04:30 AM
This is one of the reasons why we need a better documentation.
It's often not clear whether something was made intentionally or by mistake : )
-
John-David Dalton June 27th, 2008 @ 05:19 PM
- → State changed from enhancement to invalid
I am marking this invalid because if it fails the strict equality of indexOf it falls back on the traditional for loop scan.
Please Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
The Prototype JavaScript library.
