void StyleEngine::insertTreeScopeInDocumentOrder(TreeScopeSet& treeScopes, TreeScope* treeScope) { if (treeScopes.isEmpty()) { treeScopes.add(treeScope); return; } if (treeScopes.contains(treeScope)) return; TreeScopeSet::iterator begin = treeScopes.begin(); TreeScopeSet::iterator end = treeScopes.end(); TreeScopeSet::iterator it = end; TreeScope* followingTreeScope = 0; do { --it; TreeScope* n = *it; unsigned short position = n->comparePosition(*treeScope); if (position & Node::DOCUMENT_POSITION_FOLLOWING) { treeScopes.insertBefore(followingTreeScope, treeScope); return; } followingTreeScope = n; } while (it != begin); treeScopes.insertBefore(followingTreeScope, treeScope); }