From 445bfd2f28ae9f118676afc00f23fc7c3a3645f0 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 28 Dec 2009 16:54:39 +0200 Subject: Optimize ID registration Now we maintain the the ID-to-container map in the root of the tree. --- libxsd/xsd/cxx/tree/elements.hxx | 46 +++++++++++++++++----------------------- libxsd/xsd/cxx/tree/types.txx | 24 ++++++--------------- 2 files changed, 26 insertions(+), 44 deletions(-) (limited to 'libxsd/xsd/cxx/tree') 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 (&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:: 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 void id:: 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_); } -- cgit v1.1