diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2009-12-28 16:54:39 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2009-12-28 16:54:39 +0200 |
commit | 445bfd2f28ae9f118676afc00f23fc7c3a3645f0 (patch) | |
tree | bef7e669dc671b97070ba08a35505d497625b810 /libxsd/xsd/cxx/tree/elements.hxx | |
parent | f3d25e138d506d57b16bd50023e762459983ff95 (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/elements.hxx')
-rw-r--r-- | libxsd/xsd/cxx/tree/elements.hxx | 46 |
1 files changed, 20 insertions, 26 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* |