summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorArseny Kapoulkine <arseny.kapoulkine@gmail.com>2014-10-01 14:19:35 +0000
committerArseny Kapoulkine <arseny.kapoulkine@gmail.com>2014-10-01 14:19:35 +0000
commitd5dcba75583f38fc60790457a666b53fef149e92 (patch)
tree494333e8b404c7a8188edb9086317b7fec0f29c1 /src
parent290bf521fa9063b0b917d92a5fa2a94a9f4364bb (diff)
Use append_new_node in node_copy_tree
This bypasses the allow_insert check (which is redundant for copying since we're mirroring an existing node structure that must be valid) and does not cause an extra allocation for new declaration nodes. Overall results in 15% faster copying, git-svn-id: https://pugixml.googlecode.com/svn/trunk@1036 99668b35-9821-0410-8761-19e4c4f06640
Diffstat (limited to 'src')
-rw-r--r--src/pugixml.cpp29
1 files changed, 11 insertions, 18 deletions
diff --git a/src/pugixml.cpp b/src/pugixml.cpp
index 8af8dab..6297a53 100644
--- a/src/pugixml.cpp
+++ b/src/pugixml.cpp
@@ -3634,38 +3634,31 @@ PUGI__NS_BEGIN
}
}
- PUGI__FN void node_copy_contents(xml_allocator* alloc, xml_node dest, const xml_node source)
+ PUGI__FN void node_copy_contents(xml_node dest, const xml_node source, xml_allocator* shared_alloc)
{
assert(dest.type() == source.type());
xml_node_struct* dn = dest.internal_object();
xml_node_struct* sn = source.internal_object();
- node_copy_string(dn->name, dn->header, xml_memory_page_name_allocated_mask, sn->name, sn->header, alloc);
- node_copy_string(dn->value, dn->header, xml_memory_page_value_allocated_mask, sn->value, sn->header, alloc);
+ node_copy_string(dn->name, dn->header, xml_memory_page_name_allocated_mask, sn->name, sn->header, shared_alloc);
+ node_copy_string(dn->value, dn->header, xml_memory_page_value_allocated_mask, sn->value, sn->header, shared_alloc);
for (xml_attribute_struct* sa = sn->first_attribute; sa; sa = sa->next_attribute)
{
- xml_attribute_struct* da = impl::append_new_attribute(dn, impl::get_allocator(dn));
+ xml_attribute_struct* da = append_new_attribute(dn, get_allocator(dn));
- node_copy_string(da->name, da->header, xml_memory_page_name_allocated_mask, sa->name, sa->header, alloc);
- node_copy_string(da->value, da->header, xml_memory_page_value_allocated_mask, sa->value, sa->header, alloc);
+ node_copy_string(da->name, da->header, xml_memory_page_name_allocated_mask, sa->name, sa->header, shared_alloc);
+ node_copy_string(da->value, da->header, xml_memory_page_value_allocated_mask, sa->value, sa->header, shared_alloc);
}
}
- PUGI__FN xml_allocator* node_get_shared_allocator(const xml_node lhs, const xml_node rhs)
- {
- xml_allocator& la = impl::get_allocator(lhs.internal_object());
- xml_allocator& ra = impl::get_allocator(rhs.internal_object());
-
- return (&la == &ra) ? &la : 0;
- }
-
PUGI__FN void node_copy_tree(xml_node dest, const xml_node source)
{
- xml_allocator* alloc = node_get_shared_allocator(dest, source);
+ xml_allocator& alloc = get_allocator(dest.internal_object());
+ xml_allocator* shared_alloc = (&alloc == &get_allocator(source.internal_object())) ? &alloc : 0;
- node_copy_contents(alloc, dest, source);
+ node_copy_contents(dest, source, shared_alloc);
xml_node destit = dest;
xml_node sourceit = source.first_child();
@@ -3674,9 +3667,9 @@ PUGI__NS_BEGIN
{
if (sourceit != dest)
{
- xml_node copy = destit.append_child(sourceit.type());
+ xml_node copy(append_new_node(destit.internal_object(), alloc, sourceit.type()));
- node_copy_contents(alloc, copy, sourceit);
+ node_copy_contents(copy, sourceit, shared_alloc);
if (sourceit.first_child())
{