From f74a7df2df0947da7927782424924d605f11c349 Mon Sep 17 00:00:00 2001 From: Andrey Semashev Date: Sat, 28 Mar 2015 19:04:31 +0300 Subject: [PATCH] Fixed #11148. Fixed incorrect behavior of `attribute_value_set::size()` if a large number of attribute values are inserted into the set. --- doc/changelog.qbk | 1 + .../log/attributes/attribute_value_set.hpp | 2 +- src/attribute_value_set.cpp | 6 ++--- test/run/attr_attribute_value_set.cpp | 22 +++++++++++++++++++ 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/doc/changelog.qbk b/doc/changelog.qbk index a650198..942cc2e 100644 --- a/doc/changelog.qbk +++ b/doc/changelog.qbk @@ -18,6 +18,7 @@ * Fixed build failure on GNU Hurd. * Fixed incorrect behavior of [link log.detailed.sink_backends.text_file text file sink backend] in case if free space on the file system gets exhausted. The sink will no longer create lots of empty files in attempt to recover. ([ticket 11016]) * Fixed incorrect behavior of `attribute_set::insert()` in some cases. The inserted elements could have made some previously inserted elements not findable. ([ticket 11106]) +* Fixed incorrect behavior of `attribute_value_set::size()` if a large number of attribute values are inserted into the set. ([ticket 11148]) [heading 2.4, Boost 1.57] diff --git a/include/boost/log/attributes/attribute_value_set.hpp b/include/boost/log/attributes/attribute_value_set.hpp index f61da06..7aca478 100644 --- a/include/boost/log/attributes/attribute_value_set.hpp +++ b/include/boost/log/attributes/attribute_value_set.hpp @@ -330,7 +330,7 @@ public: */ BOOST_LOG_API size_type size() const; /*! - * \return true if there are no elements in the container, false otherwise. + * \return \c true if there are no elements in the container, \c false otherwise. */ bool empty() const { return (this->size() == 0); } diff --git a/src/attribute_value_set.cpp b/src/attribute_value_set.cpp index 4846b26..9c9886e 100644 --- a/src/attribute_value_set.cpp +++ b/src/attribute_value_set.cpp @@ -79,7 +79,7 @@ private: typedef intrusive::list< node, intrusive::value_traits< value_traits >, - intrusive::constant_time_size< false > + intrusive::constant_time_size< true > > node_list; //! A hash table bucket @@ -100,7 +100,7 @@ private: struct disposer { typedef void result_type; - void operator() (node* p) const + void operator() (node* p) const BOOST_NOEXCEPT { if (!p->m_DynamicallyAllocated) p->~node(); @@ -259,7 +259,7 @@ public: size_type size() { freeze(); - return (m_pEnd - m_pStorage); + return m_Nodes.size(); } //! Looks for the element with an equivalent key diff --git a/test/run/attr_attribute_value_set.cpp b/test/run/attr_attribute_value_set.cpp index a57a3a6..15fdeec 100644 --- a/test/run/attr_attribute_value_set.cpp +++ b/test/run/attr_attribute_value_set.cpp @@ -16,6 +16,7 @@ #include #include +#include #include #include #include @@ -220,3 +221,24 @@ BOOST_AUTO_TEST_CASE(lookup) BOOST_CHECK_EQUAL(view1.count(data::attr3()), 1UL); BOOST_CHECK_EQUAL(view1.count(data::attr4()), 0UL); } + +// The test checks size method +BOOST_AUTO_TEST_CASE(size) +{ + typedef logging::attribute_value_set attr_values; + attrs::constant< int > attr1(10); + + attr_values view; + view.freeze(); + + unsigned int i = 0; + for (; i < 100; ++i) + { + std::ostringstream strm; + strm << "Attr" << i; + + view.insert(attr_values::key_type(strm.str()), attr1.get_value()); + } + + BOOST_CHECK_EQUAL(view.size(), i); +}