Hi, I made a performance test: Element.hasClassName(ahref.parentNode,''myclass'') It seems this medthod is really time consuming compared to: ahref.parentNode.classNames && ahref.parentNode.classNames - Is it true ? - Should hasClassName() be used in loop or not ? I''m using prototype 1.5.1rc3 but it seems nothing change in 1.5.1 on the code I talked about. Regards -- Jean-Philippe Encausse - R&D Jalios SA Jp [at] encausse.net - http://www.encausse.com - http://www.jalias.com GTalk: jp.encausse [at] gmail.com - SMS: sms [at] jp.encausse.net Mob: +33682125699 - Job: +33139239283 - Tel: +33139189015 - Fax: +33958789015 Do it Once, Use it Twice ~ Do it Twice, Make It Once --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Christophe Porteneuve
2007-Jun-12 10:44 UTC
Re: Element.hasClassName() performance issue ?
Hey, Jean-Philippe Encausse a écrit :> It seems this medthod is really time consuming compared to:It shouldn''t. It''s actually as fast as it should get. The code you posted as comparison was obviously truncated, what''s the full version? I suspect the real cost in it is element extension, and you''re on IE... On an already-extended element, it should be very fast. Maybe there is an alternate way of achieving the overall processing you''re going for (the loop, or whatever)? -- Christophe Porteneuve aka TDD tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Jean-Philippe Encausse
2007-Jun-12 11:15 UTC
Re: Element.hasClassName() performance issue ?
Well, we saw by inspecting a simple code loop doing: $A(this.elm.getElementsByTagName(''A'')).each(function(ahref,idx){ if (!Element.hasClassName(ahref.parentNode,''disabled'')){ return; } } That hasClassName() in a "slowed" IE take the most part of the time. Well I know this loop is ugly we should use ? this.elm.down(''A.disabled''); But it is an example. So my question is: should we use Element.hasClassName() in a loop or something more straight ? On 6/12/07, Christophe Porteneuve <tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org> wrote:> > > Hey, > > Jean-Philippe Encausse a écrit : > > It seems this medthod is really time consuming compared to: > > It shouldn''t. It''s actually as fast as it should get. The code you > posted as comparison was obviously truncated, what''s the full version? > > I suspect the real cost in it is element extension, and you''re on IE... > On an already-extended element, it should be very fast. > > Maybe there is an alternate way of achieving the overall processing > you''re going for (the loop, or whatever)? > > -- > Christophe Porteneuve aka TDD > tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org > > > >-- Jean-Philippe Encausse - R&D Jalios SA Jp [at] encausse.net - http://www.encausse.com - http://www.jalias.com GTalk: jp.encausse [at] gmail.com - SMS: sms [at] jp.encausse.net Mob: +33682125699 - Job: +33139239283 - Tel: +33139189015 - Fax: +33958789015 Do it Once, Use it Twice ~ Do it Twice, Make It Once --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Christophe Porteneuve
2007-Jun-12 13:19 UTC
Re: Element.hasClassName() performance issue ?
Hey, Jean-Philippe Encausse a écrit :> But it is an example. So my question is: should we use > Element.hasClassName() in a loop > or something more straight ?The more concise code is usually better :-) After all, the $$ call will extend all elements it returns, too. Note, btw, that your call: $$(''a.disabled'') is NOT equivalent to your manual loop: it doesn''t look for disabled classes in the parent nodes of links, but on the links themselves. You''d want: $$(''.disabled > a'') However, if using hasClassName is critical for whatever reason to your code, you should not be too fearful: hasClassName, getElementsByClassName, Element.ClassNames are currently supposed to get some TLD in Prototype 1.6. -- Christophe Porteneuve aka TDD tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---