Index: testrunner.js
===================================================================
--- testrunner.js (revision 5901)
+++ testrunner.js (working copy)
@@ -428,8 +428,8 @@
if (len !== b.length) { // safe and faster
return false;
}
- for (var i = 0; i < len; i++) {
- eq = eq && equiv(a[i], b[i]);
+ for (var i = 0; i < len && eq; i++) {
+ eq = equiv(a[i], b[i]);
}
return eq;
}
@@ -447,15 +447,15 @@
// Everything in a should be in b and equivalent and ...
for (var i in a) {
- if (a.hasOwnProperty(i)) {
- eq = eq && equiv(a[i], b[i]);
+ if (!a.hasOwnProperty(i) || !equiv(a[i], b[i])) {
+ return false;
}
}
// ... everything in b should be in a and equivalent
for (var i in b) {
- if (b.hasOwnProperty(i)) {
- eq = eq && equiv(b[i], a[i]);
+ if (!b.hasOwnProperty(i) || !equiv(b[i], a[i])) {
+ return false;
}
}
On 21 Okt., 19:47, "Jörn Zaefferer" <[EMAIL PROTECTED]>
wrote:
> Could you provide these as patches against the current
> revision?http://jqueryjs.googlecode.com/svn/trunk/qunit/testrunner.js
>
> Thanks
> Jörn
>
> On Tue, Oct 21, 2008 at 7:35 PM, markus.staab <[EMAIL PROTECTED]> wrote:
>
> > even shorter
>
> > 52 for (var i in a) {
> > 53 if (!a.hasOwnProperty(i) || !equiv(a[i],
> > b[i])) {
> > 54 return false;
> > 55 }
> > 56 }
>
> > On 21 Okt., 19:07, "markus.staab" <[EMAIL PROTECTED]> wrote:
> >> taking a second look at the for (x in y) loops, we could also do some
> >> further optimization:
>
> >> 52 for (var i in a) {
> >> 53 if (a.hasOwnProperty(i)) {
> >> 54 if(!equiv(a[i], b[i]))
> >> return false;
> >> 55 } else {
> >> return false;
> >> }
> >> 56 }
>
> >> markus.staab schrieb:
>
> >> > in reply to the article athttp://philrathe.com/articles/equiv:
>
> >> > in the equiv method there is several times a loop like
>
> >> > 34 for (var i = 0; i < len; i++) {
> >> > 35 eq = eq && equiv(a[i], b[i]);
> >> > 36 }
> >> > 37 return eq;
>
> >> > this could be optimized, because if one of the elements is not equal,
> >> > you found, that the origin elements aren't equal..
>
> >> > so better use
>
> >> > 34 for (var i = 0; i < len && eq; i++) {
> >> > 35 eq = eq && equiv(a[i], b[i]);
> >> > 36 }
> >> > 37 return eq;
>
> >> > see the additional abort condition in the for loop...
> >> > This little "trick" could be applied in several places of the
> >> > function, e.g.
>
> >> > 52 for (var i in a) {
> >> > 53 if (a.hasOwnProperty(i)) {
> >> > 54 eq = eq && equiv(a[i], b[i]);
> >> > 55 }
> >> > 56 }
>
> >> > 59 for (var i in b) {
> >> > 60 if (b.hasOwnProperty(i)) {
> >> > 61 eq = eq && equiv(b[i], a[i]);
> >> > 62 }
> >> > 63 }
>
> >> > in the for(x in y) there should be a break, since there is no abort
> >> > condition.
>
> >> > greets, markus
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"jQuery Development" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---