Usage of native .classList for *className() methods when available
Firefox 3.6 implemented new .classList property for each element
(See https://developer.mozilla.org/en/DOM/element.classList for more info, HTML 5 spec http://www.whatwg.org/specs/web-apps/current-work/multipage/element... also as source)
.classList object, simply speaking, provides methods for manipulating with classes and determining if given node has given class.
There could be some performance gain when hasClassName(), addClassName() and removeClassName() methods used the classList methods (add(), remove() and contains() for setting and testing the class names). (There is a ticket in Bugzilla, which contains link to nice performance tests on following page https://bugzilla.mozilla.org/show_bug.cgi?id=501257 ).
Current support for .classList property is only in Firefox >= 3.6 (according to MDC documentation).
If you'll be interested, I could write a patch for this.
PS: Merry Christmas (for those who celebrate it :-))
Comments and changes to this ticket
I am attaching modified performace test for .classList property. (Original is from bugzilla bug #501257).
File is measuring speed between more variants of elements' class manipulation. Values should be compared against rows named "NativeClassListWrapper", as this is the fastest implementation using direct .classList calls.
I created a wrapper (PrototypeClassListWrapper), which uses original Prototype methods for class manipulation.
Then I created another two wrappers, which are using modified methods for class manipulation in a Prototype way.
Every element now contains eight another methods: element.ClassName_with_classList() and element.ClassName_with_classList_no_extension(). These methods are called in the two next Prototype test wrappers.
First methods (*ClassName_with_classList) simple replace string manipulation using regexps with calls to .classList native methods. This solution was around 200% faster than original Prototype implementation.
Second methods (*ClassName_with_classList_no_extension) are using native .classList methods as well, but in addition, element passed to the function is not being extended (no $(…) call). There was a speedup against previously mentioned implementation as well, but there was not a big difference.
All my tests were performed on firefox 3.6b5 on Windows with JIT disabled.