mirror of
https://github.com/zeux/pugixml.git
synced 2024-12-26 21:04:25 +08:00
Optimize compact mode: reuse access in insert/remove
This commit is contained in:
parent
314baf6605
commit
f388c465dd
@ -1276,12 +1276,14 @@ PUGI__NS_BEGIN
|
|||||||
|
|
||||||
child->parent = parent;
|
child->parent = parent;
|
||||||
|
|
||||||
if (node->next_sibling)
|
xml_node_struct* next = node->next_sibling;
|
||||||
node->next_sibling->prev_sibling_c = child;
|
|
||||||
|
if (next)
|
||||||
|
next->prev_sibling_c = child;
|
||||||
else
|
else
|
||||||
parent->first_child->prev_sibling_c = child;
|
parent->first_child->prev_sibling_c = child;
|
||||||
|
|
||||||
child->next_sibling = node->next_sibling;
|
child->next_sibling = next;
|
||||||
child->prev_sibling_c = node;
|
child->prev_sibling_c = node;
|
||||||
|
|
||||||
node->next_sibling = child;
|
node->next_sibling = child;
|
||||||
@ -1293,12 +1295,14 @@ PUGI__NS_BEGIN
|
|||||||
|
|
||||||
child->parent = parent;
|
child->parent = parent;
|
||||||
|
|
||||||
if (node->prev_sibling_c->next_sibling)
|
xml_node_struct* prev = node->prev_sibling_c;
|
||||||
node->prev_sibling_c->next_sibling = child;
|
|
||||||
|
if (prev->next_sibling)
|
||||||
|
prev->next_sibling = child;
|
||||||
else
|
else
|
||||||
parent->first_child = child;
|
parent->first_child = child;
|
||||||
|
|
||||||
child->prev_sibling_c = node->prev_sibling_c;
|
child->prev_sibling_c = prev;
|
||||||
child->next_sibling = node;
|
child->next_sibling = node;
|
||||||
|
|
||||||
node->prev_sibling_c = child;
|
node->prev_sibling_c = child;
|
||||||
@ -1308,15 +1312,18 @@ PUGI__NS_BEGIN
|
|||||||
{
|
{
|
||||||
xml_node_struct* parent = node->parent;
|
xml_node_struct* parent = node->parent;
|
||||||
|
|
||||||
if (node->next_sibling)
|
xml_node_struct* next = node->next_sibling;
|
||||||
node->next_sibling->prev_sibling_c = node->prev_sibling_c;
|
xml_node_struct* prev = node->prev_sibling_c;
|
||||||
else
|
|
||||||
parent->first_child->prev_sibling_c = node->prev_sibling_c;
|
|
||||||
|
|
||||||
if (node->prev_sibling_c->next_sibling)
|
if (next)
|
||||||
node->prev_sibling_c->next_sibling = node->next_sibling;
|
next->prev_sibling_c = prev;
|
||||||
else
|
else
|
||||||
parent->first_child = node->next_sibling;
|
parent->first_child->prev_sibling_c = prev;
|
||||||
|
|
||||||
|
if (prev->next_sibling)
|
||||||
|
prev->next_sibling = next;
|
||||||
|
else
|
||||||
|
parent->first_child = next;
|
||||||
|
|
||||||
node->parent = 0;
|
node->parent = 0;
|
||||||
node->prev_sibling_c = 0;
|
node->prev_sibling_c = 0;
|
||||||
@ -1360,39 +1367,46 @@ PUGI__NS_BEGIN
|
|||||||
|
|
||||||
inline void insert_attribute_after(xml_attribute_struct* attr, xml_attribute_struct* place, xml_node_struct* node)
|
inline void insert_attribute_after(xml_attribute_struct* attr, xml_attribute_struct* place, xml_node_struct* node)
|
||||||
{
|
{
|
||||||
if (place->next_attribute)
|
xml_attribute_struct* next = place->next_attribute;
|
||||||
place->next_attribute->prev_attribute_c = attr;
|
|
||||||
|
if (next)
|
||||||
|
next->prev_attribute_c = attr;
|
||||||
else
|
else
|
||||||
node->first_attribute->prev_attribute_c = attr;
|
node->first_attribute->prev_attribute_c = attr;
|
||||||
|
|
||||||
attr->next_attribute = place->next_attribute;
|
attr->next_attribute = next;
|
||||||
attr->prev_attribute_c = place;
|
attr->prev_attribute_c = place;
|
||||||
place->next_attribute = attr;
|
place->next_attribute = attr;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void insert_attribute_before(xml_attribute_struct* attr, xml_attribute_struct* place, xml_node_struct* node)
|
inline void insert_attribute_before(xml_attribute_struct* attr, xml_attribute_struct* place, xml_node_struct* node)
|
||||||
{
|
{
|
||||||
if (place->prev_attribute_c->next_attribute)
|
xml_attribute_struct* prev = place->prev_attribute_c;
|
||||||
place->prev_attribute_c->next_attribute = attr;
|
|
||||||
|
if (prev->next_attribute)
|
||||||
|
prev->next_attribute = attr;
|
||||||
else
|
else
|
||||||
node->first_attribute = attr;
|
node->first_attribute = attr;
|
||||||
|
|
||||||
attr->prev_attribute_c = place->prev_attribute_c;
|
attr->prev_attribute_c = prev;
|
||||||
attr->next_attribute = place;
|
attr->next_attribute = place;
|
||||||
place->prev_attribute_c = attr;
|
place->prev_attribute_c = attr;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void remove_attribute(xml_attribute_struct* attr, xml_node_struct* node)
|
inline void remove_attribute(xml_attribute_struct* attr, xml_node_struct* node)
|
||||||
{
|
{
|
||||||
if (attr->next_attribute)
|
xml_attribute_struct* next = attr->next_attribute;
|
||||||
attr->next_attribute->prev_attribute_c = attr->prev_attribute_c;
|
xml_attribute_struct* prev = attr->prev_attribute_c;
|
||||||
else
|
|
||||||
node->first_attribute->prev_attribute_c = attr->prev_attribute_c;
|
|
||||||
|
|
||||||
if (attr->prev_attribute_c->next_attribute)
|
if (next)
|
||||||
attr->prev_attribute_c->next_attribute = attr->next_attribute;
|
next->prev_attribute_c = prev;
|
||||||
else
|
else
|
||||||
node->first_attribute = attr->next_attribute;
|
node->first_attribute->prev_attribute_c = prev;
|
||||||
|
|
||||||
|
if (prev->next_attribute)
|
||||||
|
prev->next_attribute = next;
|
||||||
|
else
|
||||||
|
node->first_attribute = next;
|
||||||
|
|
||||||
attr->prev_attribute_c = 0;
|
attr->prev_attribute_c = 0;
|
||||||
attr->next_attribute = 0;
|
attr->next_attribute = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user