Performance suggestion: Use object hash instead of regexp

Performance suggestion: Use object hash instead of regexp


(Originally posted on jquery-en group. Reposted here on jquery-dev
following Karl Swedberg's suggestion)
I notice that jQuery uses some regexp statements like this one for
very simple matches... (used in
the position() and offsetParent() methods for example)
.../^body|html$/i.test(offsetParent.tagName)
Might it be faster to use a simple object hash like this instead...?
var test = {BODY:true, HTML:true};
...test[offsetParent.tagName];
I did some crude experiments and found that the hash technique was at
least 4 times faster in IE7 and 15 times faster in FF3.
This is only suitable for *very simple* matches of course but it could
be especially helpful in a loop.
Other people have suggested comparing the speed of a switch statement
too. The result is likely to be similar. Maybe a hash could be made
even faster by creating it once before using it repeatedly inside a
loop.
I've dumped some more info on http://blog.softwareunity.com/
I'm interested to hear people's opinions on this as a performance
booster. (What shall I call it? Sizzle perhaps? No maybe that one's
taken...)