$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r58359 - trunk/boost/serialization
From: ramey_at_[hidden]
Date: 2009-12-13 12:44:24
Author: ramey
Date: 2009-12-13 12:44:23 EST (Sun, 13 Dec 2009)
New Revision: 58359
URL: http://svn.boost.org/trac/boost/changeset/58359
Log:
Speed up loading of ordered collections
Text files modified: 
   trunk/boost/serialization/collections_load_imp.hpp      |    84 +++++++++++---------------------------- 
   trunk/boost/serialization/hash_collections_load_imp.hpp |     2                                         
   trunk/boost/serialization/hash_map.hpp                  |    60 +++++++++++++++++++++++++++             
   trunk/boost/serialization/hash_set.hpp                  |    47 +++++++++++++++++++++                   
   trunk/boost/serialization/map.hpp                       |     2                                         
   trunk/boost/serialization/set.hpp                       |     2                                         
   6 files changed, 130 insertions(+), 67 deletions(-)
Modified: trunk/boost/serialization/collections_load_imp.hpp
==============================================================================
--- trunk/boost/serialization/collections_load_imp.hpp	(original)
+++ trunk/boost/serialization/collections_load_imp.hpp	2009-12-13 12:44:23 EST (Sun, 13 Dec 2009)
@@ -50,10 +50,12 @@
 template<class Archive, class Container>
 struct archive_input_seq
 {
-    inline void operator()(
+    inline BOOST_DEDUCED_TYPENAME Container::iterator
+    operator()(
         Archive &ar, 
         Container &s, 
-        const unsigned int v
+        const unsigned int v,
+        BOOST_DEDUCED_TYPENAME Container::iterator hint
     ){
         typedef BOOST_DEDUCED_TYPENAME Container::value_type type;
         detail::stack_construct<Archive, type> t(ar, v);
@@ -61,6 +63,7 @@
         ar >> boost::serialization::make_nvp("item", t.reference());
         s.push_back(t.reference());
         ar.reset_object_address(& s.back() , & t.reference());
+        return hint;
     }
 };
 
@@ -68,51 +71,27 @@
 template<class Archive, class Container>
 struct archive_input_map
 {
-    inline void operator()(
+    inline BOOST_DEDUCED_TYPENAME Container::iterator
+    operator()(
         Archive &ar, 
         Container &s, 
-        const unsigned int v
+        const unsigned int v,
+        BOOST_DEDUCED_TYPENAME Container::iterator hint
     ){
         typedef BOOST_DEDUCED_TYPENAME Container::value_type type;
         detail::stack_construct<Archive, type> t(ar, v);
         // borland fails silently w/o full namespace
         ar >> boost::serialization::make_nvp("item", t.reference());
-        std::pair<BOOST_DEDUCED_TYPENAME Container::const_iterator, bool> result = 
-            s.insert(t.reference());
-        // note: the following presumes that the map::value_type was NOT tracked
-        // in the archive.  This is the usual case, but here there is no way
-        // to determine that.  
-        if(result.second){
-            ar.reset_object_address(
-                & (result.first->second),
-                & t.reference().second
-            );
-        }
-    }
-};
-
-// multimap input
-template<class Archive, class Container>
-struct archive_input_multimap
-{
-    inline void operator()(
-        Archive &ar, 
-        Container &s, 
-        const unsigned int v
-    ){
-        typedef BOOST_DEDUCED_TYPENAME Container::value_type type;
-        detail::stack_construct<Archive, type> t(ar, v);
-        // borland fails silently w/o full namespace
-        ar >> boost::serialization::make_nvp("item", t.reference());
-        BOOST_DEDUCED_TYPENAME Container::const_iterator result 
-            = s.insert(t.reference());
+        BOOST_DEDUCED_TYPENAME Container::iterator result = 
+            s.insert(hint, t.reference());
         // note: the following presumes that the map::value_type was NOT tracked
         // in the archive.  This is the usual case, but here there is no way
         // to determine that.  
         ar.reset_object_address(
-            & result->second,
-            & t.reference()
+            & (result->second),
+            & t.reference().second
         );
+        return result;
     }
 };
 
@@ -120,38 +99,21 @@
 template<class Archive, class Container>
 struct archive_input_set
 {
-    inline void operator()(
-        Archive &ar, 
-        Container &s, 
-        const unsigned int v
-    ){
-        typedef BOOST_DEDUCED_TYPENAME Container::value_type type;
-        detail::stack_construct<Archive, type> t(ar, v);
-        // borland fails silently w/o full namespace
-        ar >> boost::serialization::make_nvp("item", t.reference());
-        std::pair<BOOST_DEDUCED_TYPENAME Container::const_iterator, bool> result = 
-            s.insert(t.reference());
-        if(result.second)
-            ar.reset_object_address(& (* result.first), & t.reference());
-    }
-};
-
-// multiset input
-template<class Archive, class Container>
-struct archive_input_multiset
-{
-    inline void operator()(
+    inline BOOST_DEDUCED_TYPENAME Container::iterator
+    operator()(
         Archive &ar, 
         Container &s, 
-        const unsigned int v
+        const unsigned int v,
+        BOOST_DEDUCED_TYPENAME Container::iterator hint
     ){
         typedef BOOST_DEDUCED_TYPENAME Container::value_type type;
         detail::stack_construct<Archive, type> t(ar, v);
         // borland fails silently w/o full namespace
         ar >> boost::serialization::make_nvp("item", t.reference());
-        BOOST_DEDUCED_TYPENAME Container::const_iterator result 
-            = s.insert(t.reference());
+        BOOST_DEDUCED_TYPENAME Container::iterator result = 
+            s.insert(hint, t.reference());
         ar.reset_object_address(& (* result), & t.reference());
+        return result;
     }
 };
 
@@ -187,8 +149,10 @@
     rx(s, count);
     std::size_t c = count;
     InputFunction ifunc;
+    BOOST_DEDUCED_TYPENAME Container::iterator hint;
+    hint = s.begin();
     while(c-- > 0){
-        ifunc(ar, s, item_version);
+        hint = ifunc(ar, s, item_version, hint);
     }
 }
 
Modified: trunk/boost/serialization/hash_collections_load_imp.hpp
==============================================================================
--- trunk/boost/serialization/hash_collections_load_imp.hpp	(original)
+++ trunk/boost/serialization/hash_collections_load_imp.hpp	2009-12-13 12:44:23 EST (Sun, 13 Dec 2009)
@@ -20,7 +20,7 @@
 // helper function templates for serialization of hashed collections
 #include <boost/config.hpp>
 #include <boost/serialization/nvp.hpp>
-#include <boost/serialization/collections_load_imp.hpp>
+//#include <boost/serialization/collections_load_imp.hpp>
 
 namespace boost{
 namespace serialization {
Modified: trunk/boost/serialization/hash_map.hpp
==============================================================================
--- trunk/boost/serialization/hash_map.hpp	(original)
+++ trunk/boost/serialization/hash_map.hpp	2009-12-13 12:44:23 EST (Sun, 13 Dec 2009)
@@ -29,6 +29,62 @@
 namespace boost { 
 namespace serialization {
 
+namespace stl {
+
+// map input
+template<class Archive, class Container>
+struct archive_input_hash_map
+{
+    inline void operator()(
+        Archive &ar, 
+        Container &s, 
+        const unsigned int v
+    ){
+        typedef BOOST_DEDUCED_TYPENAME Container::value_type type;
+        detail::stack_construct<Archive, type> t(ar, v);
+        // borland fails silently w/o full namespace
+        ar >> boost::serialization::make_nvp("item", t.reference());
+        std::pair<BOOST_DEDUCED_TYPENAME Container::const_iterator, bool> result = 
+            s.insert(t.reference());
+        // note: the following presumes that the map::value_type was NOT tracked
+        // in the archive.  This is the usual case, but here there is no way
+        // to determine that.  
+        if(result.second){
+            ar.reset_object_address(
+                & (result.first->second),
+                & t.reference().second
+            );
+        }
+    }
+};
+
+// multimap input
+template<class Archive, class Container>
+struct archive_input_hash_multimap
+{
+    inline void operator()(
+        Archive &ar, 
+        Container &s, 
+        const unsigned int v
+    ){
+        typedef BOOST_DEDUCED_TYPENAME Container::value_type type;
+        detail::stack_construct<Archive, type> t(ar, v);
+        // borland fails silently w/o full namespace
+        ar >> boost::serialization::make_nvp("item", t.reference());
+        BOOST_DEDUCED_TYPENAME Container::const_iterator result 
+            = s.insert(t.reference());
+        // note: the following presumes that the map::value_type was NOT tracked
+        // in the archive.  This is the usual case, but here there is no way
+        // to determine that.  
+        ar.reset_object_address(
+            & result->second,
+            & t.reference()
+        );
+    }
+};
+
+} // stl
+
 template<
     class Archive, 
     class Key, 
@@ -70,7 +126,7 @@
         BOOST_STD_EXTENSION_NAMESPACE::hash_map<
             Key, HashFcn, EqualKey, Allocator
         >,
-        boost::serialization::stl::archive_input_map<
+        boost::serialization::stl::archive_input_hash_map<
             Archive, 
             BOOST_STD_EXTENSION_NAMESPACE::hash_map<
                 Key, HashFcn, EqualKey, Allocator
@@ -140,7 +196,7 @@
         BOOST_STD_EXTENSION_NAMESPACE::hash_multimap<
             Key, HashFcn, EqualKey, Allocator
         >,
-        boost::serialization::stl::archive_input_multimap<
+        boost::serialization::stl::archive_input_hash_multimap<
             Archive, 
             BOOST_STD_EXTENSION_NAMESPACE::hash_multimap<
                 Key, HashFcn, EqualKey, Allocator
Modified: trunk/boost/serialization/hash_set.hpp
==============================================================================
--- trunk/boost/serialization/hash_set.hpp	(original)
+++ trunk/boost/serialization/hash_set.hpp	2009-12-13 12:44:23 EST (Sun, 13 Dec 2009)
@@ -27,6 +27,49 @@
 namespace boost { 
 namespace serialization {
 
+namespace stl {
+
+// hash_set input
+template<class Archive, class Container>
+struct archive_input_hash_set
+{
+    inline void operator()(
+        Archive &ar, 
+        Container &s, 
+        const unsigned int v
+    ){
+        typedef BOOST_DEDUCED_TYPENAME Container::value_type type;
+        detail::stack_construct<Archive, type> t(ar, v);
+        // borland fails silently w/o full namespace
+        ar >> boost::serialization::make_nvp("item", t.reference());
+        std::pair<BOOST_DEDUCED_TYPENAME Container::const_iterator, bool> result = 
+            s.insert(t.reference());
+        if(result.second)
+            ar.reset_object_address(& (* result.first), & t.reference());
+    }
+};
+
+// hash_multiset input
+template<class Archive, class Container>
+struct archive_input_hash_multiset
+{
+    inline void operator()(
+        Archive &ar, 
+        Container &s, 
+        const unsigned int v
+    ){
+        typedef BOOST_DEDUCED_TYPENAME Container::value_type type;
+        detail::stack_construct<Archive, type> t(ar, v);
+        // borland fails silently w/o full namespace
+        ar >> boost::serialization::make_nvp("item", t.reference());
+        BOOST_DEDUCED_TYPENAME Container::const_iterator result 
+            = s.insert(t.reference());
+        ar.reset_object_address(& (* result), & t.reference());
+    }
+};
+
+} // stl
+
 template<
     class Archive, 
     class Key, 
@@ -68,7 +111,7 @@
         BOOST_STD_EXTENSION_NAMESPACE::hash_set<
             Key, HashFcn, EqualKey, Allocator
         >,
-        boost::serialization::stl::archive_input_set<
+        boost::serialization::stl::archive_input_hash_set<
             Archive, 
             BOOST_STD_EXTENSION_NAMESPACE::hash_set<
                 Key, HashFcn, EqualKey, Allocator
@@ -138,7 +181,7 @@
         BOOST_STD_EXTENSION_NAMESPACE::hash_multiset<
             Key, HashFcn, EqualKey, Allocator
         >,
-        boost::serialization::stl::archive_input_multiset<
+        boost::serialization::stl::archive_input_hash_multiset<
             Archive,
             BOOST_STD_EXTENSION_NAMESPACE::hash_multiset<
                 Key, HashFcn, EqualKey, Allocator
Modified: trunk/boost/serialization/map.hpp
==============================================================================
--- trunk/boost/serialization/map.hpp	(original)
+++ trunk/boost/serialization/map.hpp	2009-12-13 12:44:23 EST (Sun, 13 Dec 2009)
@@ -92,7 +92,7 @@
     boost::serialization::stl::load_collection<
         Archive,
         std::multimap<Key, Type, Compare, Allocator>,
-        boost::serialization::stl::archive_input_multimap<
+        boost::serialization::stl::archive_input_map<
             Archive, std::multimap<Key, Type, Compare, Allocator> 
         >,
         boost::serialization::stl::no_reserve_imp<
Modified: trunk/boost/serialization/set.hpp
==============================================================================
--- trunk/boost/serialization/set.hpp	(original)
+++ trunk/boost/serialization/set.hpp	2009-12-13 12:44:23 EST (Sun, 13 Dec 2009)
@@ -89,7 +89,7 @@
     boost::serialization::stl::load_collection<
         Archive,
         std::multiset<Key, Compare, Allocator>,
-        boost::serialization::stl::archive_input_multiset<
+        boost::serialization::stl::archive_input_set<
             Archive, std::multiset<Key, Compare, Allocator> 
         >,
         boost::serialization::stl::no_reserve_imp<