I don't quite understand what "non-capturing" means -- I'm still
pretty green when it comes to regexps -- but the rest of this makes
sense.  Clearly, a generalized regex-based solution isn't as trivial
as I made it out to be, but at least this'll work for a specific
application in a pinch.

You know, thanks to your tip, I just realized that I'm still on
Prototype 1.5.0.  Thought I'd upgraded all my projects, but missed
this one.  We'll see if 1.5.1 helps.

Altay


On May 28, 3:04 pm, Tom Gregory <[EMAIL PROTECTED]> wrote:
> For a specific application where you know the value of classes you  
> can get away with using a regex, but because it's a fragile  
> implementation, it might still be wise to avoid. (A simple == is  
> better.)  The reason it's fragile, is the regexp would also match the  
> valid class name "myclass2".  You can't just wrap the text string in  
> "\b" looking for word boundaries, because '-' is valid in class  
> names, but triggers a "word boundary".
>
> I typed out a handful of other possible optimizations for  
> hasClassName based on my recollection of how it was implemented.  
> Then I checked the source, and found these optimizations were all  
> implemented sometime around the tail end of last year (the old code,  
> which is what I remembered, was horribly inefficient). Make sure  
> you're using a recent Prototype version.  The core team put a lot of  
> work into speedup of $$, et al.
>
> ... One possible speedup of the current hasClassName code (which _is_  
> based on a regex), would be to make the groups non-capturing: several  
> of the js references I have indicate the regex is faster that way.  
> It may be worth testing.
>
> TAG
>
> On May 28, 2007, at 10:42 AM, [EMAIL PROTECTED] wrote:
>
>
>
>
>
> > Aha, if I change my custom function to use Element.hasClassName(elt,
> > 'myclass') instead of elt.className=='myclass' , then it jumps from
> > 16ms to ~250ms.  This matches $$('div.blah'), which also took
> > ~250ms.
>
> > So, FWIW, if you don't need Element.hasClassName -- that is, you're
> > only dealing with a single class -- it looks like you can score an
> > order of magnitude speed improvement by using "if
> > elt.className=='myclass'" instead.
>
> > Whoa!  Hold on... even elt.className.match('myclass') is way faster
> > (16ms) than hasClassName.  And that takes care of the multiple-
> > classname issue, right?
>
> > Has anyone done any detailed profiling of hasClassName?  Looks like
> > improvements in that might speed up IE's $$ significantly.
>
> > Altay- Hide quoted text -
>
> - Show quoted text -


--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to