include/boost/url/grammar/impl/recycled.hpp
95.2% Lines (220/231)
100.0% List of functions (38/38)
Functions (38)
Function
Calls
Lines
Blocks
boost::urls::grammar::recycled<boost::urls::grammar::implementation_defined::aligned_storage_impl<4096ul, 16ul> >::~recycled()
:22
1x
100.0%
90.0%
boost::urls::grammar::recycled<boost::urls::grammar::implementation_defined::aligned_storage_impl<8192ul, 16ul> >::~recycled()
:22
1x
100.0%
90.0%
boost::urls::grammar::recycled<boost::urls::url>::~recycled()
:22
2x
100.0%
91.0%
boost::urls::grammar::recycled<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::~recycled()
:22
1x
100.0%
91.0%
boost::urls::grammar::recycled<boost::urls::grammar::implementation_defined::aligned_storage_impl<4096ul, 16ul> >::acquire()
:45
6x
100.0%
81.0%
boost::urls::grammar::recycled<boost::urls::grammar::implementation_defined::aligned_storage_impl<8192ul, 16ul> >::acquire()
:45
4x
100.0%
81.0%
boost::urls::grammar::recycled<boost::urls::url>::acquire()
:45
2x
72.7%
69.0%
boost::urls::grammar::recycled<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::acquire()
:45
6x
100.0%
81.0%
boost::urls::grammar::recycled<boost::urls::grammar::implementation_defined::aligned_storage_impl<4096ul, 16ul> >::release(boost::urls::grammar::recycled<boost::urls::grammar::implementation_defined::aligned_storage_impl<4096ul, 16ul> >::U*)
:75
8x
100.0%
100.0%
boost::urls::grammar::recycled<boost::urls::grammar::implementation_defined::aligned_storage_impl<8192ul, 16ul> >::release(boost::urls::grammar::recycled<boost::urls::grammar::implementation_defined::aligned_storage_impl<8192ul, 16ul> >::U*)
:75
6x
100.0%
100.0%
boost::urls::grammar::recycled<boost::urls::url>::release(boost::urls::grammar::recycled<boost::urls::url>::U*)
:75
2x
87.5%
86.0%
boost::urls::grammar::recycled<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::release(boost::urls::grammar::recycled<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::U*)
:75
8x
100.0%
100.0%
boost::urls::grammar::recycled_ptr<boost::urls::grammar::implementation_defined::aligned_storage_impl<4096ul, 16ul> >::~recycled_ptr()
:95
22x
100.0%
100.0%
boost::urls::grammar::recycled_ptr<boost::urls::grammar::implementation_defined::aligned_storage_impl<8192ul, 16ul> >::~recycled_ptr()
:95
20x
100.0%
100.0%
boost::urls::grammar::recycled_ptr<boost::urls::url>::~recycled_ptr()
:95
2x
100.0%
100.0%
boost::urls::grammar::recycled_ptr<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::~recycled_ptr()
:95
8x
100.0%
100.0%
boost::urls::grammar::recycled_ptr<boost::urls::url>::recycled_ptr(boost::urls::grammar::recycled<boost::urls::url>&)
:103
1x
100.0%
100.0%
boost::urls::grammar::recycled_ptr<boost::urls::grammar::implementation_defined::aligned_storage_impl<4096ul, 16ul> >::recycled_ptr(boost::urls::grammar::recycled<boost::urls::grammar::implementation_defined::aligned_storage_impl<4096ul, 16ul> >&, decltype(nullptr))
:112
6x
100.0%
100.0%
boost::urls::grammar::recycled_ptr<boost::urls::grammar::implementation_defined::aligned_storage_impl<8192ul, 16ul> >::recycled_ptr(boost::urls::grammar::recycled<boost::urls::grammar::implementation_defined::aligned_storage_impl<8192ul, 16ul> >&, decltype(nullptr))
:112
4x
100.0%
100.0%
boost::urls::grammar::recycled_ptr<boost::urls::url>::recycled_ptr(boost::urls::grammar::recycled<boost::urls::url>&, decltype(nullptr))
:112
1x
100.0%
100.0%
boost::urls::grammar::recycled_ptr<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::recycled_ptr(boost::urls::grammar::recycled<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >&, decltype(nullptr))
:112
6x
100.0%
100.0%
boost::urls::grammar::recycled_ptr<boost::urls::grammar::implementation_defined::aligned_storage_impl<4096ul, 16ul> >::recycled_ptr()
:121
6x
100.0%
80.0%
boost::urls::grammar::recycled_ptr<boost::urls::grammar::implementation_defined::aligned_storage_impl<8192ul, 16ul> >::recycled_ptr()
:121
4x
100.0%
80.0%
boost::urls::grammar::recycled_ptr<boost::urls::url>::recycled_ptr()
:121
1x
100.0%
80.0%
boost::urls::grammar::recycled_ptr<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::recycled_ptr()
:121
6x
100.0%
80.0%
boost::urls::grammar::recycled_ptr<boost::urls::grammar::implementation_defined::aligned_storage_impl<4096ul, 16ul> >::recycled_ptr(decltype(nullptr))
:129
6x
100.0%
100.0%
boost::urls::grammar::recycled_ptr<boost::urls::grammar::implementation_defined::aligned_storage_impl<8192ul, 16ul> >::recycled_ptr(decltype(nullptr))
:129
4x
100.0%
100.0%
boost::urls::grammar::recycled_ptr<boost::urls::url>::recycled_ptr(decltype(nullptr))
:129
1x
100.0%
100.0%
boost::urls::grammar::recycled_ptr<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::recycled_ptr(decltype(nullptr))
:129
6x
100.0%
100.0%
boost::urls::grammar::recycled_ptr<boost::urls::url>::recycled_ptr(decltype(nullptr))::{lambda()#1}::operator()() const
:132
1x
100.0%
100.0%
boost::urls::grammar::recycled_ptr<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::recycled_ptr(decltype(nullptr))::{lambda()#1}::operator()() const
:132
6x
100.0%
100.0%
boost::urls::grammar::recycled_ptr<boost::urls::grammar::implementation_defined::aligned_storage_impl<4096ul, 16ul> >::recycled_ptr(boost::urls::grammar::recycled_ptr<boost::urls::grammar::implementation_defined::aligned_storage_impl<4096ul, 16ul> > const&)
:142
2x
100.0%
100.0%
boost::urls::grammar::recycled_ptr<boost::urls::grammar::implementation_defined::aligned_storage_impl<8192ul, 16ul> >::recycled_ptr(boost::urls::grammar::recycled_ptr<boost::urls::grammar::implementation_defined::aligned_storage_impl<8192ul, 16ul> > const&)
:142
2x
100.0%
100.0%
boost::urls::grammar::recycled_ptr<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::recycled_ptr(boost::urls::grammar::recycled_ptr<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > const&)
:142
2x
100.0%
100.0%
boost::urls::grammar::recycled_ptr<boost::urls::grammar::implementation_defined::aligned_storage_impl<4096ul, 16ul> >::recycled_ptr(boost::urls::grammar::recycled_ptr<boost::urls::grammar::implementation_defined::aligned_storage_impl<4096ul, 16ul> >&&)
:153
14x
100.0%
100.0%
boost::urls::grammar::recycled_ptr<boost::urls::grammar::implementation_defined::aligned_storage_impl<8192ul, 16ul> >::recycled_ptr(boost::urls::grammar::recycled_ptr<boost::urls::grammar::implementation_defined::aligned_storage_impl<8192ul, 16ul> >&&)
:153
14x
100.0%
100.0%
boost::urls::grammar::recycled_ptr<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::operator=(boost::urls::grammar::recycled_ptr<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > const&)
:180
1x
30.0%
30.0%
boost::urls::grammar::recycled_ptr<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::release()
:209
1x
100.0%
100.0%
| Line | TLA | Hits | Source Code |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2022 Vinnie Falco (vinnie.falco@gmail.com) | ||
| 3 | // | ||
| 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
| 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
| 6 | // | ||
| 7 | // Official repository: https://github.com/boostorg/url | ||
| 8 | // | ||
| 9 | |||
| 10 | #ifndef BOOST_URL_GRAMMAR_IMPL_RECYCLED_PTR_HPP | ||
| 11 | #define BOOST_URL_GRAMMAR_IMPL_RECYCLED_PTR_HPP | ||
| 12 | |||
| 13 | #include <boost/assert.hpp> | ||
| 14 | |||
| 15 | namespace boost { | ||
| 16 | namespace urls { | ||
| 17 | namespace grammar { | ||
| 18 | |||
| 19 | //------------------------------------------------ | ||
| 20 | |||
| 21 | template<class T> | ||
| 22 | 5x | recycled<T>:: | |
| 23 | ~recycled() | ||
| 24 | { | ||
| 25 | 5x | std::size_t n = 0; | |
| 26 | // VFALCO we should probably deallocate | ||
| 27 | // in reverse order of allocation but | ||
| 28 | // that requires a doubly-linked list. | ||
| 29 | 5x | auto it = head_; | |
| 30 | 12x | while(it) | |
| 31 | { | ||
| 32 | 7x | ++n; | |
| 33 | 7x | auto next = it->next; | |
| 34 | 7x | BOOST_ASSERT( | |
| 35 | it->refs == 0); | ||
| 36 | 7x | delete it; | |
| 37 | 7x | it = next; | |
| 38 | } | ||
| 39 | 5x | implementation_defined::recycled_remove( | |
| 40 | sizeof(U) * n); | ||
| 41 | 5x | } | |
| 42 | |||
| 43 | template<class T> | ||
| 44 | auto | ||
| 45 | 18x | recycled<T>:: | |
| 46 | acquire() -> | ||
| 47 | U* | ||
| 48 | { | ||
| 49 | U* p; | ||
| 50 | { | ||
| 51 | #if !defined(BOOST_URL_DISABLE_THREADS) | ||
| 52 | std::lock_guard< | ||
| 53 | 18x | std::mutex> lock(m_); | |
| 54 | #endif | ||
| 55 | 18x | p = head_; | |
| 56 | 18x | if(p) | |
| 57 | { | ||
| 58 | // reuse | ||
| 59 | 11x | head_ = head_->next; | |
| 60 | 11x | implementation_defined::recycled_remove( | |
| 61 | sizeof(U)); | ||
| 62 | 11x | ++p->refs; | |
| 63 | } | ||
| 64 | else | ||
| 65 | { | ||
| 66 | 7x | p = new U; | |
| 67 | } | ||
| 68 | 18x | } | |
| 69 | 18x | BOOST_ASSERT(p->refs == 1); | |
| 70 | 18x | return p; | |
| 71 | } | ||
| 72 | |||
| 73 | template<class T> | ||
| 74 | void | ||
| 75 | 24x | recycled<T>:: | |
| 76 | release(U* u) noexcept | ||
| 77 | { | ||
| 78 | 24x | if(--u->refs != 0) | |
| 79 | 6x | return; | |
| 80 | { | ||
| 81 | #if !defined(BOOST_URL_DISABLE_THREADS) | ||
| 82 | std::lock_guard< | ||
| 83 | 18x | std::mutex> lock(m_); | |
| 84 | #endif | ||
| 85 | 18x | u->next = head_; | |
| 86 | 18x | head_ = u; | |
| 87 | 18x | } | |
| 88 | 18x | implementation_defined::recycled_add( | |
| 89 | sizeof(U)); | ||
| 90 | } | ||
| 91 | |||
| 92 | //------------------------------------------------ | ||
| 93 | |||
| 94 | template<class T> | ||
| 95 | 52x | recycled_ptr<T>:: | |
| 96 | ~recycled_ptr() | ||
| 97 | { | ||
| 98 | 52x | if(p_) | |
| 99 | 23x | bin_->release(p_); | |
| 100 | 52x | } | |
| 101 | |||
| 102 | template<class T> | ||
| 103 | 1x | recycled_ptr<T>:: | |
| 104 | recycled_ptr( | ||
| 105 | recycled<T>& bin) | ||
| 106 | 1x | : bin_(&bin) | |
| 107 | 1x | , p_(bin.acquire()) | |
| 108 | { | ||
| 109 | 1x | } | |
| 110 | |||
| 111 | template<class T> | ||
| 112 | 17x | recycled_ptr<T>:: | |
| 113 | recycled_ptr( | ||
| 114 | recycled<T>& bin, | ||
| 115 | std::nullptr_t) noexcept | ||
| 116 | 17x | : bin_(&bin) | |
| 117 | { | ||
| 118 | 17x | } | |
| 119 | |||
| 120 | template<class T> | ||
| 121 | 17x | recycled_ptr<T>:: | |
| 122 | recycled_ptr() | ||
| 123 | 17x | : recycled_ptr(nullptr) | |
| 124 | { | ||
| 125 | 17x | p_ = bin_->acquire(); | |
| 126 | 17x | } | |
| 127 | |||
| 128 | template<class T> | ||
| 129 | 17x | recycled_ptr<T>:: | |
| 130 | recycled_ptr( | ||
| 131 | std::nullptr_t) noexcept | ||
| 132 | 24x | : recycled_ptr([]() -> B& | |
| 133 | { | ||
| 134 | // VFALCO need guaranteed constexpr-init | ||
| 135 | 7x | static B r; | |
| 136 | 7x | return r; | |
| 137 | 17x | }(), nullptr) | |
| 138 | { | ||
| 139 | 17x | } | |
| 140 | |||
| 141 | template<class T> | ||
| 142 | 6x | recycled_ptr<T>:: | |
| 143 | recycled_ptr( | ||
| 144 | recycled_ptr const& other) noexcept | ||
| 145 | 6x | : bin_(other.bin_) | |
| 146 | 6x | , p_(other.p_) | |
| 147 | { | ||
| 148 | 6x | if(p_) | |
| 149 | 6x | ++p_->refs; | |
| 150 | 6x | } | |
| 151 | |||
| 152 | template<class T> | ||
| 153 | 28x | recycled_ptr<T>:: | |
| 154 | recycled_ptr( | ||
| 155 | recycled_ptr&& other) noexcept | ||
| 156 | 28x | : bin_(other.bin_) | |
| 157 | 28x | , p_(other.p_) | |
| 158 | { | ||
| 159 | 28x | other.p_ = nullptr; | |
| 160 | 28x | } | |
| 161 | |||
| 162 | template<class T> | ||
| 163 | auto | ||
| 164 | recycled_ptr<T>:: | ||
| 165 | operator=( | ||
| 166 | recycled_ptr&& other) noexcept -> | ||
| 167 | recycled_ptr& | ||
| 168 | { | ||
| 169 | BOOST_ASSERT( | ||
| 170 | bin_ == other.bin_); | ||
| 171 | if(p_) | ||
| 172 | bin_->release(p_); | ||
| 173 | p_ = other.p_; | ||
| 174 | other.p_ = nullptr; | ||
| 175 | return *this; | ||
| 176 | } | ||
| 177 | |||
| 178 | template<class T> | ||
| 179 | auto | ||
| 180 | 1x | recycled_ptr<T>:: | |
| 181 | operator=( | ||
| 182 | recycled_ptr const& other) noexcept -> | ||
| 183 | recycled_ptr& | ||
| 184 | { | ||
| 185 | 1x | if(this == &other) | |
| 186 | 1x | return *this; | |
| 187 | ✗ | BOOST_ASSERT( | |
| 188 | bin_ == other.bin_); | ||
| 189 | ✗ | if(p_) | |
| 190 | ✗ | bin_->release(p_); | |
| 191 | ✗ | p_ = other.p_; | |
| 192 | ✗ | if(p_) | |
| 193 | ✗ | ++p_->refs; | |
| 194 | ✗ | return *this; | |
| 195 | } | ||
| 196 | |||
| 197 | template<class T> | ||
| 198 | T& | ||
| 199 | recycled_ptr<T>:: | ||
| 200 | acquire() | ||
| 201 | { | ||
| 202 | if(! p_) | ||
| 203 | p_ = bin_->acquire(); | ||
| 204 | return p_->t; | ||
| 205 | } | ||
| 206 | |||
| 207 | template<class T> | ||
| 208 | void | ||
| 209 | 1x | recycled_ptr<T>:: | |
| 210 | release() noexcept | ||
| 211 | { | ||
| 212 | 1x | if(p_) | |
| 213 | { | ||
| 214 | 1x | bin_->release(p_); | |
| 215 | 1x | p_ = nullptr; | |
| 216 | } | ||
| 217 | 1x | } | |
| 218 | |||
| 219 | } // grammar | ||
| 220 | } // urls | ||
| 221 | } // boost | ||
| 222 | |||
| 223 | #endif | ||
| 224 |