hi Philippe,
in your new code you are doing the following:
50 // Stack all property names for a last minute check for
two good reasons:
51 // 1) To prevent failing when comparing
52 // a property that have an undefined value
53 // with a property that do not exists.
54 // 2) To allow verifying equivalence in one way (a ->
b)
55 // and then comparing both property names to
replace
56 // (b -> a) processing. It's faster.
57 var aProperties = [], bProperties = [];
58
59 // Verify a's properties with b's properties
60 for (i in a) {
61 if (eq) {
62 if (a.hasOwnProperty(i)) {
63 aProperties.push(i);
64 eq = equiv(a[i], b[i]);
65 }
66 } else {
67 return false;
68 }
69 }
70
71 // Get only b's property names
72 if (eq) {
73 for (i in b) {
74 if (b.hasOwnProperty(i)) {
75 bProperties.push(i);
76 }
77 }
78 }
79
80 // Finally, ensures also the same property names in
both ways.
81 // That will also ensures that no property with
undefined value is left behind.
82 return eq && equiv(aProperties, bProperties);
in this you compare the properties from a and b twice. line 64 should
be deleted. the properties are compared in the next recursion anyway.
make the 2 "for (x in y)"-loops less complex and only collect the
properties. but then it would be optimized for the "eqiv"-case.
On 21 Okt., 22:55, Philippe Rathe <[EMAIL PROTECTED]> wrote:
> Please don't use that patch because it breaks the QUnit equiv test
> suites.
> My explanations can be found in my previous post.
>
> For some of the patched code that can be use, some benchmark need to
> be done anyway.
>
> Thanks anyway.
>
> Philippe Rathé
> On 21-Oct-08, at 2:42 PM, markus.staab wrote:
>
>
>
> > 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
-~----------~----~----~----~------~----~------~--~---