I think this should be posted at jquery-dev. There is no significant
difference between the hash and switch options, less than 10ms for
200.000 iterations (FF3). But both offer a solid speed improvement
over a simple regex in the case posted when dealing with hundreds of
calls. That could be important in case offset() is being used in an
animation function or similar.

On Feb 3, 6:05 pm, jay <jay.ab...@gmail.com> wrote:
> I imagine a switch is the same speed as a hash (switches generally
> evaluate to a hash).  Using a trie structure could be faster than
> regex in some circumstances I imagine:
>
> http://en.wikipedia.org/wiki/Trie
>
> On Feb 3, 12:45 pm, Eric Garside <gars...@gmail.com> wrote:
>
> > In that case, wouldn't a switch statement have even less overhead than
> > creating an object to check everytime? I'd think
>
> > switch(tag){case 'body':case 'html': /* ... */ break;} would be an
> > even faster solution, no?
>
> > On Feb 3, 12:39 pm, George Adamson <george.adam...@softwareunity.com>
> > wrote:
>
> > > Absolutely, it is very very limited. So this technique is only suited
> > > to the type of regex's that I quoted, like the one used internally by
> > > jquery to test for body or html tags only, or to test for t(able|d|h)
> > > only. Particulalry when used inside a loop. For parsing a selector we
> > > still need regex.
>
> > > On Feb 3, 3:16 pm, Eric Garside <gars...@gmail.com> wrote:
>
> > > > Using a hash I can see for some situations, but unless you can figure
> > > > out a way (and I'd be super interested if you could) to do complex
> > > > cascade parsing without regex, your method seems like double the work
> > > > of rewriting with no benefits towards maintainability and a minor
> > > > speed increase for only certain tags.- Hide quoted text -
>
> > - Show quoted text -

Reply via email to