Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#11457 closed enhancement (fixed)

[patch] [cla] NodeList: efficient implementation of closest()

Reported by: bill Owned by: bill
Priority: high Milestone: 1.6
Component: Core Version: 1.5
Keywords: Cc:
Blocked By: Blocking:

Description (last modified by bill)

Enhance !Nodelist.closest() to run quickly for simple selectors, avoiding running dojo.query() on the whole document (for each element of NodeList). This is a prerequisite to implementing live() and delegate().

The base issue is:

  • dojo._filterQueryResult() runs quickly but only handles simple selector, like ".foo"
  • NodeList._filterQueryResult() can handle any query (like ".foo .bar") but runs slowly (worst case O(n) where n is the number of nodes in the document).

The two functions could be combined.

After fixing dojo._filterQueryResult() to handle any selector, NodeList.orphan() etc. will start to work for any selectors.

As per http://thread.gmane.org/gmane.comp.web.dojo.devel/12516/focus=12559.

Attachments (1)

filterQueryResult.patch (7.1 KB) - added by bill 9 years ago.

Download all attachments as: .zip

Change History (6)

Changed 9 years ago by bill

Attachment: filterQueryResult.patch added

comment:1 Changed 9 years ago by bill

Description: modified (diff)

comment:2 Changed 9 years ago by James Burke

Milestone: tbd1.6
Owner: changed from anonymous to bill

Patch looks good, feel free to apply it! If you would rather I apply it, I am happy to do so, but otherwise assigning to you for 1.6.

comment:3 Changed 9 years ago by bill

Resolution: fixed
Status: newclosed

(In [22528]) Fix/enhance dojo._filterQueryResult(), NodeList.closest(), NodeList.orphan(), and NodeList.filter() to work on descendant selectors like "div > span", yet to work efficiently for simple selectors like ".foo". Fixes #11457, #11458 !strict.

Also, enhanced NodeList.closest() to take an optional root parameter (same as dojo.query()'s root parameter). If root is specified, the selector is relative to that node rather than the document root. This parameter will be useful for future NodeList.delegate(). Refs #11459.

comment:4 Changed 9 years ago by bill

(In [22529]) Lots of spelling fixes, plus fix a typo from previous check in, refs #11457 !strict.

comment:5 Changed 9 years ago by bill

(In [22537]) Make simple-filter check stricter, so that "> div" isn't classified as a simple filter. Also remove query argument from closest()'s call to _getRelatedUniqueNodes(), since it seems unnecessary (the filter has already been applied) and also since it won't work correctly without also passing in the root node that the query is relative to. Fixes #11457, #11458 !strict.

Note: See TracTickets for help on using tickets.