Honestly, I did not expect such a positive response (some even rushed to introduce the library into their projects and propagandize in every way :). For clarity, I will explain the main ideas:
This is a mini-core. To select elements of the DOM tree. On its basis (or in addition to it) you can develop other modules. But specifically, this functionality is unlikely to expand beyond CSS selectors. The idea is never new.
This is the fastest mini-core. Each line is tested and will be tested for extreme performance in most cases. To this could be the basis of a large project. Otherwise, everything else does not make sense.
The code is open (MIT + GPL). You can use anywhere (even without reference to authorship). Comments on improvements are welcome.
A little
What is this post about? The current version (0.1.6) is fairly stable with CSS1 selectors. I want some beta testing to understand the main bugs ( at the moment there is at least one controversial case: when DOM-methods and main libraries choose a different number of elements for example, with non-unique selections).
Raised a separate host for the library itself and check the speed: yass.webo.in there is also a test environment raised with most libraries (thanks to lusever for contributing) yass.webo.in/slickspeed Of course, this is all CSS1. But for this and thought ')
List of changes:
0.1.1: reduced the number of operations before taking from the cache. Added another basic case ( form type)
0.1.2: replace + split for groups replaced by split with regular (thanks to tenshi ), array sizes corrected (to pass SlickSpeed)
0.1.3: reduced the number of calls to internal variables ( _.nodes , _.sets ), introduced a new “greedy” regular schedule (now the restriction is on JS 1.5, thanks to GreLI ). A new parameter has been added: the search root (second) is not yet everywhere, but for non-basic cases. The caching prohibition is shifted to the third parameter. The slowest version (to figure out why :)
0.1.4: if-then-else expressions are replaced by ||. The conditions in the while loop are replaced by checking the presence of the corresponding elements. A minor bug has been fixed in Opera (verification for nodeName has been introduced). Calling properties of the form '[]' replaced by '.' (thanks, arty )
0.1.5: use getElementsByClassName implemented. document.all replaced by document.getElementById (the latter is still faster, or there is no difference).
0.1.6: getElementsByClassName left only in front of the general case: in general, the tag is always selected and then the class and ID are checked. A check is implemented before the regular expression for #id (probably, it is worth removing the check for the same after the regular check - it is worth checking).
Performance increased (compared to 0.1) by: Fx3 (70%), Opera 9.6 (24%), IE7 (37%), Safari (13%). The main changes in productivity: 0.1 -> 0.1.1, 0.1.2 -> 0.1.4, 0.1.4 -> 0.1.6
As soon as I connect SVN via code.google, I’ll post a link.
Small todo
Implement checking for attributes (selectors of the form [name=value]:first-child and different variations) without loss of performance to get closer to CSS3
Make and test a selection of a subtree.
Add garbage for cache ( cache , in theory, should flow well in IE).
To do something with the uniqueness of the returned items (a sample is now returned, which may contain several identical elements)