Skip to content

Commit

Permalink
compressor: s/boost::optional/std::optional/
Browse files Browse the repository at this point in the history
prefer facilities provided by standard library over the ones in
3rd party libraries.

Signed-off-by: Kefu Chai <[email protected]>
  • Loading branch information
tchaikov committed Mar 22, 2022
1 parent 217c328 commit ebb577e
Show file tree
Hide file tree
Showing 17 changed files with 71 additions and 71 deletions.
6 changes: 3 additions & 3 deletions src/compressor/Compressor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const char* Compressor::get_comp_alg_name(int a) {
return p->first;
}

boost::optional<Compressor::CompressionAlgorithm>
std::optional<Compressor::CompressionAlgorithm>
Compressor::get_comp_alg_type(std::string_view s) {

auto p = std::find_if(std::cbegin(compression_algorithms), std::cend(compression_algorithms),
Expand All @@ -61,7 +61,7 @@ const char *Compressor::get_comp_mode_name(int m) {
default: return "???";
}
}
boost::optional<Compressor::CompressionMode>
std::optional<Compressor::CompressionMode>
Compressor::get_comp_mode_type(std::string_view s) {
if (s == "force")
return COMP_FORCE;
Expand All @@ -71,7 +71,7 @@ Compressor::get_comp_mode_type(std::string_view s) {
return COMP_PASSIVE;
if (s == "none")
return COMP_NONE;
return boost::optional<CompressionMode>();
return {};
}

CompressorRef Compressor::create(CephContext *cct, const std::string &type)
Expand Down
12 changes: 6 additions & 6 deletions src/compressor/Compressor.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
#define CEPH_COMPRESSOR_H

#include <memory>
#include <optional>
#include <string>
#include <string_view>
#include <boost/optional.hpp>
#include "include/ceph_assert.h" // boost clobbers this
#include "include/common_fwd.h"
#include "include/buffer.h"
Expand Down Expand Up @@ -76,10 +76,10 @@ class Compressor {
#endif

static const char* get_comp_alg_name(int a);
static boost::optional<CompressionAlgorithm> get_comp_alg_type(std::string_view s);
static std::optional<CompressionAlgorithm> get_comp_alg_type(std::string_view s);

static const char *get_comp_mode_name(int m);
static boost::optional<CompressionMode> get_comp_mode_type(std::string_view s);
static std::optional<CompressionMode> get_comp_mode_type(std::string_view s);

Compressor(CompressionAlgorithm a, const char* t) : alg(a), type(t) {
}
Expand All @@ -90,11 +90,11 @@ class Compressor {
CompressionAlgorithm get_type() const {
return alg;
}
virtual int compress(const ceph::bufferlist &in, ceph::bufferlist &out, boost::optional<int32_t> &compressor_message) = 0;
virtual int decompress(const ceph::bufferlist &in, ceph::bufferlist &out, boost::optional<int32_t> compressor_message) = 0;
virtual int compress(const ceph::bufferlist &in, ceph::bufferlist &out, std::optional<int32_t> &compressor_message) = 0;
virtual int decompress(const ceph::bufferlist &in, ceph::bufferlist &out, std::optional<int32_t> compressor_message) = 0;
// this is a bit weird but we need non-const iterator to be in
// alignment with decode methods
virtual int decompress(ceph::bufferlist::const_iterator &p, size_t compressed_len, ceph::bufferlist &out, boost::optional<int32_t> compressor_message) = 0;
virtual int decompress(ceph::bufferlist::const_iterator &p, size_t compressed_len, ceph::bufferlist &out, std::optional<int32_t> compressor_message) = 0;

static CompressorRef create(CephContext *cct, const std::string &type);
static CompressorRef create(CephContext *cct, int alg);
Expand Down
6 changes: 3 additions & 3 deletions src/compressor/QatAccel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ bool QatAccel::init(const std::string &alg) {
return true;
}

int QatAccel::compress(const bufferlist &in, bufferlist &out, boost::optional<int32_t> &compressor_message) {
int QatAccel::compress(const bufferlist &in, bufferlist &out, std::optional<int32_t> &compressor_message) {
auto s = get_session(); // get a session from the pool
if (!s) {
return -1; // session initialization failed
Expand All @@ -169,15 +169,15 @@ int QatAccel::compress(const bufferlist &in, bufferlist &out, boost::optional<in
return 0;
}

int QatAccel::decompress(const bufferlist &in, bufferlist &out, boost::optional<int32_t> compressor_message) {
int QatAccel::decompress(const bufferlist &in, bufferlist &out, std::optional<int32_t> compressor_message) {
auto i = in.begin();
return decompress(i, in.length(), out, compressor_message);
}

int QatAccel::decompress(bufferlist::const_iterator &p,
size_t compressed_len,
bufferlist &dst,
boost::optional<int32_t> compressor_message) {
std::optional<int32_t> compressor_message) {
auto s = get_session(); // get a session from the pool
if (!s) {
return -1; // session initialization failed
Expand Down
8 changes: 4 additions & 4 deletions src/compressor/QatAccel.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
#ifndef CEPH_QATACCEL_H
#define CEPH_QATACCEL_H

#include <boost/optional.hpp>
#include <condition_variable>
#include <memory>
#include <mutex>
#include <optional>
#include <vector>

#include "include/buffer.h"
Expand All @@ -37,9 +37,9 @@ class QatAccel {

bool init(const std::string &alg);

int compress(const bufferlist &in, bufferlist &out, boost::optional<int32_t> &compressor_message);
int decompress(const bufferlist &in, bufferlist &out, boost::optional<int32_t> compressor_message);
int decompress(bufferlist::const_iterator &p, size_t compressed_len, bufferlist &dst, boost::optional<int32_t> compressor_message);
int compress(const bufferlist &in, bufferlist &out, std::optional<int32_t> &compressor_message);
int decompress(const bufferlist &in, bufferlist &out, std::optional<int32_t> compressor_message);
int decompress(bufferlist::const_iterator &p, size_t compressed_len, bufferlist &dst, std::optional<int32_t> compressor_message);

private:
// get a session from the pool or create a new one. returns null if session init fails
Expand Down
6 changes: 3 additions & 3 deletions src/compressor/lz4/LZ4Compressor.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class LZ4Compressor : public Compressor {
#endif
}

int compress(const ceph::buffer::list &src, ceph::buffer::list &dst, boost::optional<int32_t> &compressor_message) override {
int compress(const ceph::buffer::list &src, ceph::buffer::list &dst, std::optional<int32_t> &compressor_message) override {
// older versions of liblz4 introduce bit errors when compressing
// fragmented buffers. this was fixed in lz4 commit
// af127334670a5e7b710bbd6adb71aa7c3ef0cd72, which first
Expand Down Expand Up @@ -83,7 +83,7 @@ class LZ4Compressor : public Compressor {
return 0;
}

int decompress(const ceph::buffer::list &src, ceph::buffer::list &dst, boost::optional<int32_t> compressor_message) override {
int decompress(const ceph::buffer::list &src, ceph::buffer::list &dst, std::optional<int32_t> compressor_message) override {
#ifdef HAVE_QATZIP
if (qat_enabled)
return qat_accel.decompress(src, dst, compressor_message);
Expand All @@ -95,7 +95,7 @@ class LZ4Compressor : public Compressor {
int decompress(ceph::buffer::list::const_iterator &p,
size_t compressed_len,
ceph::buffer::list &dst,
boost::optional<int32_t> compressor_message) override {
std::optional<int32_t> compressor_message) override {
#ifdef HAVE_QATZIP
if (qat_enabled)
return qat_accel.decompress(p, compressed_len, dst, compressor_message);
Expand Down
6 changes: 3 additions & 3 deletions src/compressor/snappy/SnappyCompressor.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class SnappyCompressor : public Compressor {
#endif
}

int compress(const ceph::bufferlist &src, ceph::bufferlist &dst, boost::optional<int32_t> &compressor_message) override {
int compress(const ceph::bufferlist &src, ceph::bufferlist &dst, std::optional<int32_t> &compressor_message) override {
#ifdef HAVE_QATZIP
if (qat_enabled)
return qat_accel.compress(src, dst, compressor_message);
Expand All @@ -80,7 +80,7 @@ class SnappyCompressor : public Compressor {
return 0;
}

int decompress(const ceph::bufferlist &src, ceph::bufferlist &dst, boost::optional<int32_t> compressor_message) override {
int decompress(const ceph::bufferlist &src, ceph::bufferlist &dst, std::optional<int32_t> compressor_message) override {
#ifdef HAVE_QATZIP
if (qat_enabled)
return qat_accel.decompress(src, dst, compressor_message);
Expand All @@ -92,7 +92,7 @@ class SnappyCompressor : public Compressor {
int decompress(ceph::bufferlist::const_iterator &p,
size_t compressed_len,
ceph::bufferlist &dst,
boost::optional<int32_t> compressor_message) override {
std::optional<int32_t> compressor_message) override {
#ifdef HAVE_QATZIP
if (qat_enabled)
return qat_accel.decompress(p, compressed_len, dst, compressor_message);
Expand Down
10 changes: 5 additions & 5 deletions src/compressor/zlib/ZlibCompressor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ _prefix(std::ostream* _dout)
// compression ratio.
#define ZLIB_MEMORY_LEVEL 8

int ZlibCompressor::zlib_compress(const bufferlist &in, bufferlist &out, boost::optional<int32_t> &compressor_message)
int ZlibCompressor::zlib_compress(const bufferlist &in, bufferlist &out, std::optional<int32_t> &compressor_message)
{
int ret;
unsigned have;
Expand Down Expand Up @@ -114,7 +114,7 @@ int ZlibCompressor::zlib_compress(const bufferlist &in, bufferlist &out, boost::
}

#if __x86_64__ && defined(HAVE_NASM_X64_AVX2)
int ZlibCompressor::isal_compress(const bufferlist &in, bufferlist &out, boost::optional<int32_t> &compressor_message)
int ZlibCompressor::isal_compress(const bufferlist &in, bufferlist &out, std::optional<int32_t> &compressor_message)
{
int ret;
unsigned have;
Expand Down Expand Up @@ -168,7 +168,7 @@ int ZlibCompressor::isal_compress(const bufferlist &in, bufferlist &out, boost::
}
#endif

int ZlibCompressor::compress(const bufferlist &in, bufferlist &out, boost::optional<int32_t> &compressor_message)
int ZlibCompressor::compress(const bufferlist &in, bufferlist &out, std::optional<int32_t> &compressor_message)
{
#ifdef HAVE_QATZIP
if (qat_enabled)
Expand All @@ -184,7 +184,7 @@ int ZlibCompressor::compress(const bufferlist &in, bufferlist &out, boost::optio
#endif
}

int ZlibCompressor::decompress(bufferlist::const_iterator &p, size_t compressed_size, bufferlist &out, boost::optional<int32_t> compressor_message)
int ZlibCompressor::decompress(bufferlist::const_iterator &p, size_t compressed_size, bufferlist &out, std::optional<int32_t> compressor_message)
{
#ifdef HAVE_QATZIP
if (qat_enabled)
Expand Down Expand Up @@ -244,7 +244,7 @@ int ZlibCompressor::decompress(bufferlist::const_iterator &p, size_t compressed_
return 0;
}

int ZlibCompressor::decompress(const bufferlist &in, bufferlist &out, boost::optional<int32_t> compressor_message)
int ZlibCompressor::decompress(const bufferlist &in, bufferlist &out, std::optional<int32_t> compressor_message)
{
auto i = std::cbegin(in);
return decompress(i, in.length(), out, compressor_message);
Expand Down
10 changes: 5 additions & 5 deletions src/compressor/zlib/ZlibCompressor.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ class ZlibCompressor : public Compressor {
#endif
}

int compress(const ceph::buffer::list &in, ceph::buffer::list &out, boost::optional<int32_t> &compressor_message) override;
int decompress(const ceph::buffer::list &in, ceph::buffer::list &out, boost::optional<int32_t> compressor_message) override;
int decompress(ceph::buffer::list::const_iterator &p, size_t compressed_len, ceph::buffer::list &out, boost::optional<int32_t> compressor_message) override;
int compress(const ceph::buffer::list &in, ceph::buffer::list &out, std::optional<int32_t> &compressor_message) override;
int decompress(const ceph::buffer::list &in, ceph::buffer::list &out, std::optional<int32_t> compressor_message) override;
int decompress(ceph::buffer::list::const_iterator &p, size_t compressed_len, ceph::buffer::list &out, std::optional<int32_t> compressor_message) override;
private:
int zlib_compress(const ceph::buffer::list &in, ceph::buffer::list &out, boost::optional<int32_t> &compressor_message);
int isal_compress(const ceph::buffer::list &in, ceph::buffer::list &out, boost::optional<int32_t> &compressor_message);
int zlib_compress(const ceph::buffer::list &in, ceph::buffer::list &out, std::optional<int32_t> &compressor_message);
int isal_compress(const ceph::buffer::list &in, ceph::buffer::list &out, std::optional<int32_t> &compressor_message);
};


Expand Down
6 changes: 3 additions & 3 deletions src/compressor/zstd/ZstdCompressor.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ZstdCompressor : public Compressor {
public:
ZstdCompressor(CephContext *cct) : Compressor(COMP_ALG_ZSTD, "zstd"), cct(cct) {}

int compress(const ceph::buffer::list &src, ceph::buffer::list &dst, boost::optional<int32_t> &compressor_message) override {
int compress(const ceph::buffer::list &src, ceph::buffer::list &dst, std::optional<int32_t> &compressor_message) override {
ZSTD_CStream *s = ZSTD_createCStream();
ZSTD_initCStream_srcSize(s, cct->_conf->compressor_zstd_level, src.length());
auto p = src.begin();
Expand Down Expand Up @@ -61,15 +61,15 @@ class ZstdCompressor : public Compressor {
return 0;
}

int decompress(const ceph::buffer::list &src, ceph::buffer::list &dst, boost::optional<int32_t> compressor_message) override {
int decompress(const ceph::buffer::list &src, ceph::buffer::list &dst, std::optional<int32_t> compressor_message) override {
auto i = std::cbegin(src);
return decompress(i, src.length(), dst, compressor_message);
}

int decompress(ceph::buffer::list::const_iterator &p,
size_t compressed_len,
ceph::buffer::list &dst,
boost::optional<int32_t> compressor_message) override {
std::optional<int32_t> compressor_message) override {
if (compressed_len < 4) {
return -1;
}
Expand Down
4 changes: 2 additions & 2 deletions src/msg/async/compression_onwire.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ std::optional<ceph::bufferlist> TxHandler::compress(const ceph::bufferlist &inpu
return out;
}

boost::optional<int32_t> compressor_message;
std::optional<int32_t> compressor_message;
if (m_compressor->compress(input, out, compressor_message)) {
return {};
} else {
Expand All @@ -68,7 +68,7 @@ std::optional<ceph::bufferlist> RxHandler::decompress(const ceph::bufferlist &in
return out;
}

boost::optional<int32_t> compressor_message;
std::optional<int32_t> compressor_message;
if (m_compressor->decompress(input, out, compressor_message)) {
return {};
} else {
Expand Down
26 changes: 13 additions & 13 deletions src/os/bluestore/BlueStore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15314,9 +15314,9 @@ int BlueStore::_do_alloc_write(
}
}
}
return boost::optional<CompressorRef>(cp);
return std::optional<CompressorRef>(cp);
}
return boost::optional<CompressorRef>();
return std::optional<CompressorRef>();
}
);

Expand All @@ -15326,9 +15326,9 @@ int BlueStore::_do_alloc_write(
[&]() {
double val;
if (coll->pool_opts.get(pool_opts_t::COMPRESSION_REQUIRED_RATIO, &val)) {
return boost::optional<double>(val);
return std::optional<double>(val);
}
return boost::optional<double>();
return std::optional<double>();
}
);
}
Expand All @@ -15341,9 +15341,9 @@ int BlueStore::_do_alloc_write(
[&]() {
int64_t val;
if (coll->pool_opts.get(pool_opts_t::CSUM_TYPE, &val)) {
return boost::optional<int64_t>(val);
return std::optional<int64_t>(val);
}
return boost::optional<int64_t>();
return std::optional<int64_t>();
}
);

Expand All @@ -15360,7 +15360,7 @@ int BlueStore::_do_alloc_write(

// FIXME: memory alignment here is bad
bufferlist t;
boost::optional<int32_t> compressor_message;
std::optional<int32_t> compressor_message;
int r = c->compress(wi.bl, t, compressor_message);
uint64_t want_len_raw = wi.blob_length * crr;
uint64_t want_len = p2roundup(want_len_raw, min_alloc_size);
Expand Down Expand Up @@ -15796,10 +15796,10 @@ void BlueStore::_choose_write_options(
[&]() {
string val;
if (c->pool_opts.get(pool_opts_t::COMPRESSION_MODE, &val)) {
return boost::optional<Compressor::CompressionMode>(
return std::optional<Compressor::CompressionMode>(
Compressor::get_comp_mode_type(val));
}
return boost::optional<Compressor::CompressionMode>();
return std::optional<Compressor::CompressionMode>();
}
);

Expand Down Expand Up @@ -15832,9 +15832,9 @@ void BlueStore::_choose_write_options(
[&]() {
int64_t val;
if (c->pool_opts.get(pool_opts_t::COMPRESSION_MAX_BLOB_SIZE, &val)) {
return boost::optional<uint64_t>((uint64_t)val);
return std::optional<uint64_t>((uint64_t)val);
}
return boost::optional<uint64_t>();
return std::optional<uint64_t>();
}
);
}
Expand All @@ -15846,9 +15846,9 @@ void BlueStore::_choose_write_options(
[&]() {
int64_t val;
if (c->pool_opts.get(pool_opts_t::COMPRESSION_MIN_BLOB_SIZE, &val)) {
return boost::optional<uint64_t>((uint64_t)val);
return std::optional<uint64_t>((uint64_t)val);
}
return boost::optional<uint64_t>();
return std::optional<uint64_t>();
}
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/os/bluestore/BlueStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -2743,7 +2743,7 @@ class BlueStore : public ObjectStore,
template <typename T, typename F>
T select_option(const std::string& opt_name, T val1, F f) {
//NB: opt_name reserved for future use
boost::optional<T> val2 = f();
std::optional<T> val2 = f();
if (val2) {
return *val2;
}
Expand Down
2 changes: 1 addition & 1 deletion src/os/bluestore/bluestore_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,7 @@ WRITE_CLASS_DENC(bluestore_deferred_transaction_t)
struct bluestore_compression_header_t {
uint8_t type = Compressor::COMP_ALG_NONE;
uint32_t length = 0;
boost::optional<int32_t> compressor_message;
std::optional<int32_t> compressor_message;

bluestore_compression_header_t() {}
bluestore_compression_header_t(uint8_t _type)
Expand Down
4 changes: 2 additions & 2 deletions src/rgw/rgw_compression.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class RGWPutObj_Compress : public rgw::putobj::Pipe
CephContext* cct;
bool compressed{false};
CompressorRef compressor;
boost::optional<int32_t> compressor_message;
std::optional<int32_t> compressor_message;
std::vector<compression_block> blocks;
public:
RGWPutObj_Compress(CephContext* cct_, CompressorRef compressor,
Expand All @@ -56,7 +56,7 @@ class RGWPutObj_Compress : public rgw::putobj::Pipe

bool is_compressed() { return compressed; }
std::vector<compression_block>& get_compression_blocks() { return blocks; }
boost::optional<int32_t> get_compressor_message() { return compressor_message; }
std::optional<int32_t> get_compressor_message() { return compressor_message; }

}; /* RGWPutObj_Compress */

Expand Down
Loading

0 comments on commit ebb577e

Please sign in to comment.