[PATCH] Remove redundant loop in unsynchronized_pool_resource code

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] Remove redundant loop in unsynchronized_pool_resource code

Jonathan Wakely-3
        * src/c++17/memory_resource.cc (bitset::find_first_unset()): Remove
        unused function.
        (bitset::get_first_unset()): Remove loop, if there's are unset bits
        then _M_next_word refers to the first one and there's no need to loop.
        (_Pool::_Pool(size_t, size_t), _Pool::block_size()): Remove dead code.

Tested x86_64-linux, committed to trunk.



patch.txt (3K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Remove redundant loop in unsynchronized_pool_resource code

Jonathan Wakely-3
On 13/11/18 22:59 +0000, Jonathan Wakely wrote:
> * src/c++17/memory_resource.cc (bitset::find_first_unset()): Remove
> unused function.
> (bitset::get_first_unset()): Remove loop, if there's are unset bits
> then _M_next_word refers to the first one and there's no need to loop.
> (_Pool::_Pool(size_t, size_t), _Pool::block_size()): Remove dead code.


>     size_type get_first_unset() noexcept
>     {
>-      for (size_type i = _M_next_word; i < nwords(); ++i)
>+      if (_M_next_word < nwords())
> {
>-  const size_type n = std::__countr_one(_M_words[i]);
>+  const size_type n = std::__countr_one(_M_words[_M_next_word]);
>  if (n < bits_per_word)
>    {
>      const word bit = word(1) << n;
>-      _M_words[i] |= bit;
>-      if (i == _M_next_word)
>+      _M_words[_M_next_word] |= bit;
>+      const size_t res = (_M_next_word * bits_per_word) + n;
>+      if (n == (bits_per_word - 1))
> update_next_word();
>-      return (i * bits_per_word) + n;
>+      return res;
>    }
> }
>       return size_type(-1);

I'm not sure why, but this version seems to perform measurably worse.
I'll investigate, and maybe revert the change.