I believe the point made by Ariel about non-local access is to be
taken in high consideration. As he said, the gain obtained by caching
very small expressions may be lost due to non-local variable access.
So changes should be done only where a speed improvement can be
achieved and verified.

The trim() case was solved and the problem was not about caching of
the regular expression but maybe a too complicated RegExp for the
task. A simpler one was enough.

As I said, I was following the trim() thread, spotting some ideas on
what could be wrong.

So speed is not a concern, readability maybe, if it doesn't slow down
code execution.

Diego


On 2 Feb, 17:19, John Resig <jere...@gmail.com> wrote:
> It depends - if there's a considerable amount of duplicate code it
> would be good to cut down on that (using the same regex over and over,
> for example).
>
> --John
>
> On Mon, Feb 2, 2009 at 8:40 AM, Ariel Flesler <afles...@gmail.com> wrote:
>
> > Why patch it, John ? there's no speed gain and I actually think it'd
> > make things slower.
> > If you save the regex in a var within the upper scope, each access
> > will take longer than if it were 100% local.
>
> > --
> > Ariel Flesler
> >http://flesler.blogspot.com
>
> > On Feb 1, 10:09 pm, John Resig <jere...@gmail.com> wrote:
> >> Ah, ok. I suspect that some of that may be in Sizzle. Patches are welcome!
>
> >> --John
>
> >> On Sun, Feb 1, 2009 at 2:14 PM, Diego Perini <diego.per...@gmail.com> 
> >> wrote:
>
> >> > 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 <jere...@gmail.com> 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 <diego.per...@gmail.com> 
> >> >> 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- Hide quoted text -
>
> >> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery Development" group.
To post to this group, send email to jquery-dev@googlegroups.com
To unsubscribe from this group, send email to 
jquery-dev+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to