From 95c80ed1d5bffe3cd8ee6a6deb8044171167acd6 Mon Sep 17 00:00:00 2001 From: liuchang0812 Date: Mon, 13 Feb 2017 17:59:28 +0800 Subject: [PATCH] cleanup: use boost::algorithm::ends_with in bluestore Signed-off-by: liuchang0812 --- src/os/bluestore/BlueFS.cc | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/os/bluestore/BlueFS.cc b/src/os/bluestore/BlueFS.cc index 4f80ec464e6..f1928ac0757 100644 --- a/src/os/bluestore/BlueFS.cc +++ b/src/os/bluestore/BlueFS.cc @@ -1,6 +1,7 @@ // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab +#include "boost/algorithm/string.hpp" #include "BlueFS.h" #include "common/debug.h" @@ -8,6 +9,7 @@ #include "common/perf_counters.h" #include "BlockDevice.h" #include "Allocator.h" +#include "include/assert.h" #define dout_context cct #define dout_subsys ceph_subsys_bluefs @@ -1917,9 +1919,9 @@ int BlueFS::open_for_write( // match up with bluestore. the slow device is always the second // one (when a dedicated block.db device is present and used at // bdev 0). the wal device is always last. - if (strcmp(dirname.c_str() + dirname.length() - 5, ".slow") == 0) { + if (boost::algorithm::ends_with(filename, ".slow")) { file->fnode.prefer_bdev = BlueFS::BDEV_SLOW; - } else if (strcmp(dirname.c_str() + dirname.length() - 4, ".wal") == 0) { + } else if (boost::algorithm::ends_with(dirname, ".wal")) { file->fnode.prefer_bdev = BlueFS::BDEV_WAL; } } @@ -1932,12 +1934,12 @@ int BlueFS::open_for_write( *h = _create_writer(file); - if (0 == filename.compare(filename.length() - 4, 4, ".log")) { + if (boost::algorithm::ends_with(filename, ".log")) { (*h)->writer_type = BlueFS::WRITER_WAL; if (logger && !overwrite) { logger->inc(l_bluefs_files_written_wal); } - } else if (0 == filename.compare(filename.length() - 4, 4, ".sst")) { + } else if (boost::algorithm::ends_with(filename, ".sst")) { (*h)->writer_type = BlueFS::WRITER_SST; if (logger) { logger->inc(l_bluefs_files_written_sst); @@ -2177,7 +2179,7 @@ int BlueFS::readdir(const string& dirname, vector *ls) { std::lock_guard l(lock); dout(10) << __func__ << " " << dirname << dendl; - if (dirname.size() == 0) { + if (dirname.empty()) { // list dirs ls->reserve(dir_map.size() + 2); for (auto& q : dir_map) { -- 2.47.3