X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=ceph%2Fsrc%2Fboost%2Fboost%2Fcontainer%2Fstring.hpp;h=516b701aa4ed71e353c0a2867d601c5e786f924d;hb=92f5a8d42d07f9929ae4fa7e01342fe8d96808a8;hp=8829fdaadb5d432dff798fd2a91c251767961a54;hpb=a0324939f9d0e1905d5df8f57442f09dc70af83d;p=ceph.git diff --git a/ceph/src/boost/boost/container/string.hpp b/ceph/src/boost/boost/container/string.hpp index 8829fdaad..516b701aa 100644 --- a/ceph/src/boost/boost/container/string.hpp +++ b/ceph/src/boost/boost/container/string.hpp @@ -87,9 +87,9 @@ class basic_string_base basic_string_base & operator=(const basic_string_base &); basic_string_base(const basic_string_base &); - typedef allocator_traits allocator_traits_type; + typedef Allocator allocator_type; public: - typedef Allocator allocator_type; + typedef allocator_traits allocator_traits_type; typedef allocator_type stored_allocator_type; typedef typename allocator_traits_type::pointer pointer; typedef typename allocator_traits_type::value_type value_type; @@ -98,27 +98,25 @@ class basic_string_base basic_string_base() : members_() - { init(); } + {} explicit basic_string_base(const allocator_type& a) : members_(a) - { init(); } + {} explicit basic_string_base(BOOST_RV_REF(allocator_type) a) : members_(boost::move(a)) - { this->init(); } + {} basic_string_base(const allocator_type& a, size_type n) : members_(a) { - this->init(); this->allocate_initial_block(n); } explicit basic_string_base(size_type n) : members_() { - this->init(); this->allocate_initial_block(n); } @@ -140,6 +138,11 @@ class basic_string_base pointer start; long_t() + : is_short(0) + {} + + long_t(size_type len, size_type stor, pointer ptr) + : is_short(0), length(len), storage(stor), start(ptr) {} long_t(const long_t &other) @@ -190,43 +193,57 @@ class basic_string_base value_type data[UnalignedFinalInternalBufferChars]; }; - union repr_t + union repr_t_size_t { long_raw_t r; short_t s; + }; - const short_t &short_repr() const - { return s; } - - const long_t &long_repr() const - { return *static_cast(static_cast(r.data)); } - - short_t &short_repr() - { return s; } - - long_t &long_repr() - { return *static_cast(static_cast(&r)); } + union repr_t + { + long_raw_t r_aligner; + short_t s_aligner; + unsigned char data[sizeof(repr_t_size_t)]; }; struct members_holder - : public Allocator + : public allocator_type { + void init() + { + short_t &s = *::new(this->m_repr.data) short_t; + s.h.is_short = 1; + s.h.length = 0; + } + members_holder() - : Allocator() - {} + : allocator_type() + { this->init(); } template explicit members_holder(BOOST_FWD_REF(AllocatorConvertible) a) - : Allocator(boost::forward(a)) - {} + : allocator_type(boost::forward(a)) + { this->init(); } + + const short_t *pshort_repr() const + { return reinterpret_cast(m_repr.data); } + + const long_t *plong_repr() const + { return reinterpret_cast(m_repr.data); } + + short_t *pshort_repr() + { return reinterpret_cast(m_repr.data); } + + long_t *plong_repr() + { return reinterpret_cast(m_repr.data); } repr_t m_repr; } members_; - const Allocator &alloc() const + const allocator_type &alloc() const { return members_; } - Allocator &alloc() + allocator_type &alloc() { return members_; } static const size_type InternalBufferChars = (sizeof(repr_t) - ShortDataOffset)/sizeof(value_type); @@ -246,36 +263,55 @@ class basic_string_base return hdr.is_short != 0; } - void is_short(bool yes) + short_t *construct_short() { - const bool was_short = this->is_short(); - if(yes && !was_short){ - allocator_traits_type::destroy - ( this->alloc() - , static_cast(static_cast(&this->members_.m_repr.r)) - ); - this->members_.m_repr.s.h.is_short = true; - } - else if(!yes && was_short){ - allocator_traits_type::construct - ( this->alloc() - , static_cast(static_cast(&this->members_.m_repr.r)) - ); - this->members_.m_repr.s.h.is_short = false; + short_t *ps = ::new(this->members_.m_repr.data) short_t; + ps->h.is_short = 1; + return ps; + } + + void destroy_short() + { + BOOST_ASSERT(this->is_short()); + this->members_.pshort_repr()->~short_t(); + } + + short_t *assure_short() + { + if (!this->is_short()){ + this->destroy_long(); + return construct_short(); } + return this->members_.pshort_repr(); } - private: - void init() + long_t *construct_long() + { + long_t *pl = ::new(this->members_.m_repr.data) long_t; + //is_short flag is written in the constructor + return pl; + } + + void destroy_long() + { + BOOST_ASSERT(!this->is_short()); + this->members_.plong_repr()->~long_t(); + } + + long_t *assure_long() { - this->members_.m_repr.s.h.is_short = 1; - this->members_.m_repr.s.h.length = 0; + if (this->is_short()){ + this->destroy_short(); + return this->construct_long(); + } + return this->members_.plong_repr(); } + protected: typedef dtl::integral_constant::value> alloc_version; + boost::container::dtl::version::value> alloc_version; pointer allocation_command(allocation_type command, size_type limit_size, @@ -286,7 +322,7 @@ class basic_string_base reuse = 0; command &= ~(expand_fwd | expand_bwd); } - return dtl::allocator_version_traits::allocation_command + return dtl::allocator_version_traits::allocation_command (this->alloc(), command, limit_size, prefer_in_recvd_out_size, reuse); } @@ -334,7 +370,8 @@ class basic_string_base size_type new_cap = this->next_capacity(n); pointer reuse = 0; pointer p = this->allocation_command(allocate_new, n, new_cap, reuse); - this->is_short(false); + BOOST_ASSERT(this->is_short()); + this->construct_long(); this->priv_long_addr(p); this->priv_long_size(0); this->priv_storage(new_cap); @@ -356,10 +393,16 @@ class basic_string_base { return this->priv_storage() - 1; } pointer priv_short_addr() const - { return pointer_traits::pointer_to(const_cast(this->members_.m_repr.short_repr().data[0])); } + { return pointer_traits::pointer_to(const_cast(this->members_.pshort_repr()->data[0])); } + + //GCC seems a bit confused about uninitialized accesses + #if defined(BOOST_GCC) && (BOOST_GCC >= 40700) + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" + #endif pointer priv_long_addr() const - { return this->members_.m_repr.long_repr().start; } + { return this->members_.plong_repr()->start; } pointer priv_addr() const { @@ -378,7 +421,7 @@ class basic_string_base } void priv_long_addr(pointer addr) - { this->members_.m_repr.long_repr().start = addr; } + { this->members_.plong_repr()->start = addr; } size_type priv_storage() const { return this->is_short() ? priv_short_storage() : priv_long_storage(); } @@ -387,7 +430,7 @@ class basic_string_base { return InternalBufferChars; } size_type priv_long_storage() const - { return this->members_.m_repr.long_repr().storage; } + { return this->members_.plong_repr()->storage; } void priv_storage(size_type storage) { @@ -397,17 +440,17 @@ class basic_string_base void priv_long_storage(size_type storage) { - this->members_.m_repr.long_repr().storage = storage; + this->members_.plong_repr()->storage = storage; } size_type priv_size() const { return this->is_short() ? this->priv_short_size() : this->priv_long_size(); } size_type priv_short_size() const - { return this->members_.m_repr.short_repr().h.length; } + { return this->members_.pshort_repr()->h.length; } size_type priv_long_size() const - { return this->members_.m_repr.long_repr().length; } + { return this->members_.plong_repr()->length; } void priv_size(size_type sz) { @@ -418,14 +461,14 @@ class basic_string_base } void priv_short_size(size_type sz) - { - this->members_.m_repr.s.h.length = (unsigned char)sz; - } + { this->members_.pshort_repr()->h.length = (unsigned char)sz; } void priv_long_size(size_type sz) - { - this->members_.m_repr.long_repr().length = sz; - } + { this->members_.plong_repr()->length = sz; } + + #if defined(BOOST_GCC) && (BOOST_GCC >= 40700) + #pragma GCC diagnostic pop + #endif void swap_data(basic_string_base& other) { @@ -436,23 +479,23 @@ class basic_string_base other.members_.m_repr = tmp; } else{ - short_t short_backup(this->members_.m_repr.short_repr()); - this->members_.m_repr.short_repr().~short_t(); - ::new(&this->members_.m_repr.long_repr()) long_t(other.members_.m_repr.long_repr()); - other.members_.m_repr.long_repr().~long_t(); - ::new(&other.members_.m_repr.short_repr()) short_t(short_backup); + short_t short_backup(*this->members_.pshort_repr()); + this->members_.pshort_repr()->~short_t(); + ::new(this->members_.plong_repr()) long_t(*other.members_.plong_repr()); + other.members_.plong_repr()->~long_t(); + ::new(other.members_.pshort_repr()) short_t(short_backup); } } else{ if(other.is_short()){ - short_t short_backup(other.members_.m_repr.short_repr()); - other.members_.m_repr.short_repr().~short_t(); - ::new(&other.members_.m_repr.long_repr()) long_t(this->members_.m_repr.long_repr()); - this->members_.m_repr.long_repr().~long_t(); - ::new(&this->members_.m_repr.short_repr()) short_t(short_backup); + short_t short_backup(*other.members_.pshort_repr()); + other.members_.pshort_repr()->~short_t(); + ::new(other.members_.plong_repr()) long_t(*this->members_.plong_repr()); + this->members_.plong_repr()->~long_t(); + ::new(this->members_.pshort_repr()) short_t(short_backup); } else{ - boost::adl_move_swap(this->members_.m_repr.long_repr(), other.members_.m_repr.long_repr()); + boost::adl_move_swap(*this->members_.plong_repr(), *other.members_.plong_repr()); } } } @@ -495,18 +538,18 @@ class basic_string_base //! \tparam Traits The Character Traits type, which encapsulates basic character operations //! \tparam Allocator The allocator, used for internal memory management. #ifdef BOOST_CONTAINER_DOXYGEN_INVOKED -template , class Allocator = new_allocator > +template , class Allocator = void > #else template #endif class basic_string - : private dtl::basic_string_base + : private dtl::basic_string_base::type> { #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED private: - typedef allocator_traits allocator_traits_type; BOOST_COPYABLE_AND_MOVABLE(basic_string) - typedef dtl::basic_string_base base_t; + typedef dtl::basic_string_base::type> base_t; + typedef typename base_t::allocator_traits_type allocator_traits_type; static const typename base_t::size_type InternalBufferChars = base_t::InternalBufferChars; protected: @@ -553,13 +596,13 @@ class basic_string ////////////////////////////////////////////// typedef Traits traits_type; typedef CharT value_type; - typedef typename ::boost::container::allocator_traits::pointer pointer; - typedef typename ::boost::container::allocator_traits::const_pointer const_pointer; - typedef typename ::boost::container::allocator_traits::reference reference; - typedef typename ::boost::container::allocator_traits::const_reference const_reference; - typedef typename ::boost::container::allocator_traits::size_type size_type; - typedef typename ::boost::container::allocator_traits::difference_type difference_type; - typedef Allocator allocator_type; + typedef typename real_allocator::type allocator_type; + typedef typename ::boost::container::allocator_traits::pointer pointer; + typedef typename ::boost::container::allocator_traits::const_pointer const_pointer; + typedef typename ::boost::container::allocator_traits::reference reference; + typedef typename ::boost::container::allocator_traits::const_reference const_reference; + typedef typename ::boost::container::allocator_traits::size_type size_type; + typedef typename ::boost::container::allocator_traits::difference_type difference_type; typedef BOOST_CONTAINER_IMPDEF(allocator_type) stored_allocator_type; typedef BOOST_CONTAINER_IMPDEF(pointer) iterator; typedef BOOST_CONTAINER_IMPDEF(const_pointer) const_iterator; @@ -596,7 +639,7 @@ class basic_string //! Effects: Default constructs a basic_string. //! //! Throws: If allocator_type's default constructor throws. - basic_string() BOOST_NOEXCEPT_IF(dtl::is_nothrow_default_constructible::value) + basic_string() BOOST_NOEXCEPT_IF(dtl::is_nothrow_default_constructible::value) : base_t() { this->priv_terminate_string(); } @@ -624,7 +667,7 @@ class basic_string //! //! Throws: If allocator_type's default constructor or allocation throws. template