Stephen Woodbridge schrieb:
> OK, here is an interesting tidbit.
>
> I used the test below and and did the 7 click thing, and out of all my 
> tests except one, the long delay happened in has() and once I got it in 
> find(). has() is pretty simple and I wonder if this has less to do with 
> the number of clicks versus the number of regex's we use and dispose or 
> something like that.
>
> I love testing!!! It makes one look at what is happening and sometimes 
> you are surprised! but the questions and introspection are always good 
> on occasion.
>   
That is an interesting point. I wonder if it makes sense to cache 
regular expressions. Eg:

function cache(expression, options) {
    var key = expression + options || "";
    var regex = cache[key];
    if(!regex) {
       regex = cache[key] = new RegExp(expression, options);
    }
    return regex;
}

Appending the options to the cache key should prevent any ambiguity. The 
intersting questions: Is it more efficient to cache regular expressions 
then to let the garbage collected?

-- 
Jörn Zaefferer

http://bassistance.de


_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to