John,
well I did some small test with:

/\s+/
/\\/g

and it seems there is no appreciable speed gain that I could measure.

I spotted those shorter RegExp because I saw they are re-used at least
4 or 5 times in current jQuery.

Thanks to jdalton for the link and explanation.


Diego


On 1 Feb, 15:53, John Resig <[email protected]> wrote:
> Is there any appreciable speed-up to caching RegExp that are that
> small? I wasn't able to find any when I looked.
>
> --John
>
> On Sun, Feb 1, 2009 at 7:58 AM, Diego Perini <[email protected]> wrote:
>
> > I did have a quick look through the code and see that most of the
> > (small) regular expressions are not cached and referenced but defined
> > in-line in the conditionals/replacements.
>
> > For example these are repeatedly used in various place:
>
> > /\s+/
> > /\\/g
> > /\?/
>
> > I believe there are improvements in both speed and readability of code
> > by caching them compiled.
>
> > Is there some reason I don't know in not defining some constants like
> > TRIM, SQUEEZE, ESCAPE etc... ?
>
> > Diego
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to