summaryrefslogtreecommitdiff
path: root/libxsd/xsd/cxx/tree
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2009-12-28 16:54:39 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2009-12-28 16:54:39 +0200
commit445bfd2f28ae9f118676afc00f23fc7c3a3645f0 (patch)
treebef7e669dc671b97070ba08a35505d497625b810 /libxsd/xsd/cxx/tree
parentf3d25e138d506d57b16bd50023e762459983ff95 (diff)
Optimize ID registration
Now we maintain the the ID-to-container map in the root of the tree.
Diffstat (limited to 'libxsd/xsd/cxx/tree')
-rw-r--r--libxsd/xsd/cxx/tree/elements.hxx46
-rw-r--r--libxsd/xsd/cxx/tree/types.txx24
2 files changed, 26 insertions, 44 deletions
diff --git a/libxsd/xsd/cxx/tree/elements.hxx b/libxsd/xsd/cxx/tree/elements.hxx
index 3334d5f..c48839a 100644
--- a/libxsd/xsd/cxx/tree/elements.hxx
+++ b/libxsd/xsd/cxx/tree/elements.hxx
@@ -425,13 +425,20 @@ namespace xsd
{
if (map_.get () != 0)
{
- // Propagate our IDs to the new container.
+ // Propagate our IDs to the new root.
//
- for (map::iterator i (map_->begin ()), e (map_->end ());
- i != e; ++i)
+ container* r (c->_root ());
+
+ if (r == 0)
+ r = c;
+
+ if (r->map_.get () != 0)
{
- c->_register_id (*i->first, i->second);
+ r->map_->insert (map_->begin (), map_->end ());
+ map_.reset ();
}
+ else
+ r->map_ = map_;
}
container_ = c;
@@ -585,16 +592,13 @@ namespace xsd
void
_register_id (const identity& id, type* t)
{
+ // We should be the root.
+ //
+ assert (container_ == 0);
+
if (map_.get () == 0)
map_.reset (new map);
- // First register on our container. If there are any duplications,
- // they will be detected by this call and we don't need to clean
- // the map.
- //
- if (container_ != 0)
- container_->_register_id (id, t);
-
if (!map_->insert (
std::pair<const identity*, type*> (&id, t)).second)
{
@@ -616,22 +620,12 @@ namespace xsd
void
_unregister_id (const identity& id)
{
- if (map_.get ())
- {
- map::iterator it (map_->find (&id));
-
- if (it != map_->end ())
- {
- map_->erase (it);
-
- if (container_ != 0)
- container_->_unregister_id (id);
-
- return;
- }
- }
+ // We should be the root.
+ //
+ assert (container_ == 0);
- throw not_registered ();
+ if (map_.get () == 0 || map_->erase (&id) == 0)
+ throw not_registered ();
}
type*
diff --git a/libxsd/xsd/cxx/tree/types.txx b/libxsd/xsd/cxx/tree/types.txx
index 799c5fa..7c9d696 100644
--- a/libxsd/xsd/cxx/tree/types.txx
+++ b/libxsd/xsd/cxx/tree/types.txx
@@ -185,32 +185,20 @@ namespace xsd
void id<C, B>::
register_id ()
{
- container* c (this->_container ());
+ container* r (this->_root ());
- if (c != 0 && !this->empty ())
- {
- //std::cerr << "registering " << c
- // << " as '" << *this
- // << "' on " << c << std::endl;
-
- c->_register_id (identity_, c);
- }
+ if (r != 0 && !this->empty ())
+ r->_register_id (identity_, this->_container ());
}
template <typename C, typename B>
void id<C, B>::
unregister_id ()
{
- container* c (this->_container ());
+ container* r (this->_root ());
- if (c != 0 && !this->empty ())
- {
- //std::cerr << "un-registering " << c
- // << " as '" << *this
- // << "' on " << c << std::endl;
-
- c->_unregister_id (identity_);
- }
+ if (r != 0 && !this->empty ())
+ r->_unregister_id (identity_);
}