The basic idea is to only match against id selectors which might matter by keeping track of them in a hashtable instead of a flat list. We still need to use a flat list for possibly-negated id selectors, unfortunately.