]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commit
common/bl: c_str() examines length instead of no. of bptrs.
authorRadoslaw Zarzynski <rzarzyns@redhat.com>
Mon, 19 Jul 2021 13:55:18 +0000 (13:55 +0000)
committerRadoslaw Zarzynski <rzarzyns@redhat.com>
Tue, 20 Jul 2021 14:29:34 +0000 (14:29 +0000)
commitedf3bbc004409098b9bb3ec7a369a99b51cb131a
tree4030f5a5eeff14bd97bd4965a2907a3dfd6f75ed
parentac001cbd2ee154be98108cd1d1277fb73037eda5
common/bl: c_str() examines length instead of no. of bptrs.

This approach has 2 adventages:
* it takes into consideration the specical case of a bufferlist
  that carries solely empty bptrs while
* allowing compilers to optimize-out the load-and-check of `_len`
  we already do in `rebuild()` which is called by `c_str()`.

  ```cpp
  void buffer::list::rebuild()
  {
    if (_len == 0) {
      _carriage = &always_empty_bptr;
      _buffers.clear_and_dispose();
      _num = 0;
      return;
    }
    // ...
  }
  ```

Signed-off-by: Radoslaw Zarzynski <rzarzyns@redhat.com>
src/common/buffer.cc