XPath: Restored document order sorting optimization (it's now automatic for nodes that were loaded and not significantly altered), minor traversal optimizations
git-svn-id: http://pugixml.googlecode.com/svn/trunk@613 99668b35-9821-0410-8761-19e4c4f06640
This commit is contained in:
parent
0363bccfc9
commit
93bb5dcb43
@ -3216,8 +3216,13 @@ namespace pugi
|
|||||||
return (_attr && _attr->value) ? _attr->value : PUGIXML_TEXT("");
|
return (_attr && _attr->value) ? _attr->value : PUGIXML_TEXT("");
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int xml_attribute::document_order() const
|
const void* xml_attribute::document_order() const
|
||||||
{
|
{
|
||||||
|
if (!_attr) return 0;
|
||||||
|
|
||||||
|
if ((_attr->header & xml_memory_page_name_allocated_mask) == 0) return _attr->name;
|
||||||
|
if ((_attr->header & xml_memory_page_value_allocated_mask) == 0) return _attr->value;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4014,8 +4019,13 @@ namespace pugi
|
|||||||
return walker.end(arg_end);
|
return walker.end(arg_end);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int xml_node::document_order() const
|
const void* xml_node::document_order() const
|
||||||
{
|
{
|
||||||
|
if (!_root) return 0;
|
||||||
|
|
||||||
|
if (_root->name && (_root->header & xml_memory_page_name_allocated_mask) == 0) return _root->name;
|
||||||
|
if (_root->value && (_root->header & xml_memory_page_value_allocated_mask) == 0) return _root->value;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -646,8 +646,7 @@ namespace pugi
|
|||||||
bool as_bool() const;
|
bool as_bool() const;
|
||||||
|
|
||||||
/// \internal Document order or 0 if not set
|
/// \internal Document order or 0 if not set
|
||||||
/// \deprecated This function is deprecated
|
const void* document_order() const;
|
||||||
PUGIXML_DEPRECATED unsigned int document_order() const;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
@ -1466,8 +1465,7 @@ namespace pugi
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/// \internal Document order or 0 if not set
|
/// \internal Document order or 0 if not set
|
||||||
/// \deprecated This function is deprecated
|
const void* document_order() const;
|
||||||
PUGIXML_DEPRECATED unsigned int document_order() const;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Print subtree to writer
|
* Print subtree to writer
|
||||||
|
|||||||
@ -143,28 +143,22 @@ namespace
|
|||||||
|
|
||||||
xml_node cur = n.first_child();
|
xml_node cur = n.first_child();
|
||||||
|
|
||||||
if (cur)
|
while (cur && cur != n)
|
||||||
{
|
{
|
||||||
do
|
if (cur.type() == node_pcdata || cur.type() == node_cdata)
|
||||||
|
result += cur.value();
|
||||||
|
|
||||||
|
if (cur.first_child())
|
||||||
|
cur = cur.first_child();
|
||||||
|
else if (cur.next_sibling())
|
||||||
|
cur = cur.next_sibling();
|
||||||
|
else
|
||||||
{
|
{
|
||||||
if (cur.type() == node_pcdata || cur.type() == node_cdata)
|
while (!cur.next_sibling() && cur != n)
|
||||||
result += cur.value();
|
cur = cur.parent();
|
||||||
|
|
||||||
if (cur.first_child())
|
if (cur != n) cur = cur.next_sibling();
|
||||||
cur = cur.first_child();
|
|
||||||
else if (cur.next_sibling())
|
|
||||||
cur = cur.next_sibling();
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Borland C++ workaround
|
|
||||||
while (!cur.next_sibling() && cur != n && (bool)cur.parent())
|
|
||||||
cur = cur.parent();
|
|
||||||
|
|
||||||
if (cur != n)
|
|
||||||
cur = cur.next_sibling();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
while (cur && cur != n);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@ -228,6 +222,11 @@ namespace
|
|||||||
{
|
{
|
||||||
xml_node ln = lhs.node(), rn = rhs.node();
|
xml_node ln = lhs.node(), rn = rhs.node();
|
||||||
|
|
||||||
|
const void* lo = lhs.attribute() ? lhs.attribute().document_order() : ln.document_order();
|
||||||
|
const void* ro = rhs.attribute() ? rhs.attribute().document_order() : rn.document_order();
|
||||||
|
|
||||||
|
if (lo && ro) return lo < ro;
|
||||||
|
|
||||||
if (lhs.attribute() && rhs.attribute())
|
if (lhs.attribute() && rhs.attribute())
|
||||||
{
|
{
|
||||||
if (lhs.parent() == rhs.parent())
|
if (lhs.parent() == rhs.parent())
|
||||||
@ -1642,27 +1641,21 @@ namespace pugi
|
|||||||
|
|
||||||
xml_node cur = n.first_child();
|
xml_node cur = n.first_child();
|
||||||
|
|
||||||
if (cur)
|
while (cur && cur != n)
|
||||||
{
|
{
|
||||||
do
|
step_push(ns, cur);
|
||||||
|
|
||||||
|
if (cur.first_child())
|
||||||
|
cur = cur.first_child();
|
||||||
|
else if (cur.next_sibling())
|
||||||
|
cur = cur.next_sibling();
|
||||||
|
else
|
||||||
{
|
{
|
||||||
step_push(ns, cur);
|
while (!cur.next_sibling() && cur != n)
|
||||||
|
cur = cur.parent();
|
||||||
|
|
||||||
if (cur.first_child())
|
if (cur != n) cur = cur.next_sibling();
|
||||||
cur = cur.first_child();
|
|
||||||
else if (cur.next_sibling())
|
|
||||||
cur = cur.next_sibling();
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Borland C++ workaround
|
|
||||||
while (!cur.next_sibling() && cur != n && (bool)cur.parent())
|
|
||||||
cur = cur.parent();
|
|
||||||
|
|
||||||
if (cur != n)
|
|
||||||
cur = cur.next_sibling();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
while (cur && cur != n);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user