summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2009-11-08 14:23:40 +0000
committerarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2009-11-08 14:23:40 +0000
commit74737f97ba86199fb2be4ae91a2d0f3743c9a5e5 (patch)
treefaa8f9f689e56e7bd0e327abfaec0b479ca140bf /src
parent48bbb9f4dd9e6581e61d4d60e132cdb4415f813e (diff)
XPath: Node set copy now preserves sorted flag (for performance and consistency), removed redundant m_using_storage internal flag
git-svn-id: http://pugixml.googlecode.com/svn/trunk@222 99668b35-9821-0410-8761-19e4c4f06640
Diffstat (limited to 'src')
-rw-r--r--src/pugixml.hpp2
-rw-r--r--src/pugixpath.cpp20
2 files changed, 11 insertions, 11 deletions
diff --git a/src/pugixml.hpp b/src/pugixml.hpp
index 3ed6229..3f23e01 100644
--- a/src/pugixml.hpp
+++ b/src/pugixml.hpp
@@ -1947,8 +1947,6 @@ namespace pugi
xpath_node* m_end;
xpath_node* m_eos;
- bool m_using_storage;
-
typedef xpath_node* iterator;
iterator mut_begin();
diff --git a/src/pugixpath.cpp b/src/pugixpath.cpp
index f2e0e56..27a11d7 100644
--- a/src/pugixpath.cpp
+++ b/src/pugixpath.cpp
@@ -657,36 +657,37 @@ namespace pugi
}
#endif
- xpath_node_set::xpath_node_set(): m_type(type_unsorted), m_begin(&m_storage), m_end(&m_storage), m_eos(&m_storage + 1), m_using_storage(true)
+ xpath_node_set::xpath_node_set(): m_type(type_unsorted), m_begin(&m_storage), m_end(&m_storage), m_eos(&m_storage + 1)
{
}
xpath_node_set::~xpath_node_set()
{
- if (!m_using_storage) delete[] m_begin;
+ if (m_begin != &m_storage) delete[] m_begin;
}
- xpath_node_set::xpath_node_set(const xpath_node_set& ns): m_type(type_unsorted), m_begin(&m_storage), m_end(&m_storage), m_eos(&m_storage + 1), m_using_storage(true)
+ xpath_node_set::xpath_node_set(const xpath_node_set& ns): m_type(type_unsorted), m_begin(&m_storage), m_end(&m_storage), m_eos(&m_storage + 1)
{
*this = ns;
}
xpath_node_set& xpath_node_set::operator=(const xpath_node_set& ns)
{
- if (!m_using_storage) delete[] m_begin;
+ if (&ns == this) return *this;
+
+ if (m_begin != &m_storage) delete[] m_begin;
m_begin = m_end = m_eos = 0;
+ m_type = ns.m_type;
if (ns.size() == 1)
{
m_storage = *ns.m_begin;
m_begin = &m_storage;
m_end = m_eos = &m_storage + 1;
- m_using_storage = true;
}
else
{
- m_using_storage = false;
append(ns.begin(), ns.end());
}
@@ -764,9 +765,7 @@ namespace pugi
xpath_node* storage = new xpath_node[capacity];
std::copy(m_begin, m_end, storage);
- if (!m_using_storage) delete[] m_begin;
-
- m_using_storage = false;
+ if (m_begin != &m_storage) delete[] m_begin;
m_begin = storage;
m_end = storage + size;
@@ -2375,6 +2374,9 @@ namespace pugi
xpath_node_set ls = m_left->eval_node_set(c);
xpath_node_set rs = m_right->eval_node_set(c);
+ // we can optimize merging two sorted sets, but this is a very rare operation, so don't bother
+ ls.m_type = xpath_node_set::type_unsorted;
+
ls.append(rs.begin(), rs.end());
ls.remove_duplicates();