Given the results of your testing, do you intend to propose a patch
for Prototype?
May I suggest that adding non-capturing groups to the RegExp may be
the tiniest bit faster? This is untested supposition, and I'd be
quite interested to see your results if you chose to test it.
new RegExp("(?:^|\\s)" + className + "(?:\\s|$)")
TAG
On Jun 21, 2006, at 1:10 PM, Eric Anderson wrote:
One more problem to consider. If you use the $$() instead of
document.getElementsByClassName() it will use Element.hasClassName
() which is much slower than using a regular expression. So prior
to using the $$() function you might want to do:
Element.hasClassName = function(element, className) {
return element.className.match(new RegExp("(^|\\s)" +
className + "(\\s|$)"));
};
This will cause Element.hasClassName() to use the same
implementation that document.getElementsByClassName() uses which in
my tests produces much better performance because it is a simple
regex (builtin to Javascript and therefore fast) instead of
splitting each classname, constructing an object and then iterating
over each item in the collection to determine if the class exists.
Eric
_______________________________________________
Rails-spinoffs mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs