Bug 120248

Summary: Element child and descendant iterators
Product: WebKit Reporter: Antti Koivisto <koivisto>
Component: DOMAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: andersca, darin, eflews.bot, gtk-ews, gyuyoung.kim, kling, philn, webkit-ews, xan.lopez
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
maybe something along these lines
none
patch
none
another
webkit-ews: commit-queue-
yet another sam: review+

Antti Koivisto
Reported 2013-08-24 09:33:46 PDT
Better approach to iterating.
Attachments
maybe something along these lines (9.35 KB, patch)
2013-08-24 12:39 PDT, Antti Koivisto
no flags
patch (31.80 KB, patch)
2013-08-25 11:48 PDT, Antti Koivisto
no flags
another (31.88 KB, patch)
2013-08-25 11:51 PDT, Antti Koivisto
webkit-ews: commit-queue-
yet another (36.26 KB, patch)
2013-08-25 13:56 PDT, Antti Koivisto
sam: review+
Antti Koivisto
Comment 1 2013-08-24 12:39:52 PDT
Created attachment 209551 [details] maybe something along these lines
Andreas Kling
Comment 2 2013-08-24 12:50:13 PDT
Comment on attachment 209551 [details] maybe something along these lines I think this would be absolutely magical with C++11 range-based for loops. I also think get() should return an Element& and we can have something like getPtr() for Element*. (This to encourage ourselves to use references.)
Darin Adler
Comment 3 2013-08-24 14:46:17 PDT
Will look nice in C++11 for loops. When we use element pointers, it’s well defined what happens if the document changes while we are iterating. For iterators, we’d want to define what happens in that case. What our hash tables do with iterators is that in debug versions they invalidate iterators when changes are made to the underlying data structure. Maybe we could do some variation on that.
Darin Adler
Comment 4 2013-08-24 14:46:55 PDT
(In reply to comment #2) > I also think get() should return an Element& and we can have something like getPtr() for Element*. (This to encourage ourselves to use references.) C++ iterators normally use *iterator, not iterator.get().
Andreas Kling
Comment 5 2013-08-24 14:48:53 PDT
Comment on attachment 209551 [details] maybe something along these lines View in context: https://bugs.webkit.org/attachment.cgi?id=209551&action=review > Source/WebCore/dom/ElementTraversal.h:107 > + bool operator!=(const ElementDescendantIterator& other) const { return m_current != other.m_current; } This method could assert that both iterators have the same root.
Antti Koivisto
Comment 6 2013-08-24 23:43:49 PDT
(In reply to comment #3) > Will look nice in C++11 for loops. > > When we use element pointers, it’s well defined what happens if the document changes while we are iterating. For iterators, we’d want to define what happens in that case. What our hash tables do with iterators is that in debug versions they invalidate iterators when changes are made to the underlying data structure. Maybe we could do some variation on that. Yeah. I think we should assert that there are no tree mutations during iteration. Not just in the current subtree, in the entire tree.
Darin Adler
Comment 7 2013-08-24 23:49:25 PDT
(In reply to comment #6) > Yeah. I think we should assert that there are no tree mutations during iteration. Not just in the current subtree, in the entire tree. Should probably go further and also assert that no DOM events were dispatched. An event handler could have mutated the tree; just because it didn’t actually happen does not mean the code is OK.
Antti Koivisto
Comment 8 2013-08-25 11:48:09 PDT
Antti Koivisto
Comment 9 2013-08-25 11:51:54 PDT
Early Warning System Bot
Comment 10 2013-08-25 11:59:38 PDT
Early Warning System Bot
Comment 11 2013-08-25 12:01:53 PDT
EFL EWS Bot
Comment 12 2013-08-25 12:07:56 PDT
Comment on attachment 209596 [details] another Attachment 209596 [details] did not pass efl-wk2-ews (efl-wk2): Output: http://webkit-queues.appspot.com/results/1544952
EFL EWS Bot
Comment 13 2013-08-25 12:14:15 PDT
kov's GTK+ EWS bot
Comment 14 2013-08-25 12:56:17 PDT
kov's GTK+ EWS bot
Comment 15 2013-08-25 13:35:16 PDT
Antti Koivisto
Comment 16 2013-08-25 13:56:06 PDT
Created attachment 209603 [details] yet another
Sam Weinig
Comment 17 2013-08-25 14:00:49 PDT
Comment on attachment 209603 [details] yet another View in context: https://bugs.webkit.org/attachment.cgi?id=209603&action=review > Source/WebCore/WebCore.vcxproj/WebCore.vcxproj:-1 > -<?xml version="1.0" encoding="utf-8"?> Removing this was probably a mistake.
Antti Koivisto
Comment 18 2013-08-25 14:30:37 PDT
Note You need to log in before you can comment on or make changes to this bug.