Skip to content

Commit

Permalink
refactor: replace folly::split with dwarfs::split_to
Browse files Browse the repository at this point in the history
  • Loading branch information
mhx committed Aug 13, 2024
1 parent 4a7a993 commit 6c12a04
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 26 deletions.
11 changes: 4 additions & 7 deletions src/internal/worker_group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@

#include <fmt/format.h>

#include <folly/String.h>
#include <folly/portability/Windows.h>
#include <folly/system/ThreadName.h>

#include <dwarfs/error.h>
#include <dwarfs/logger.h>
#include <dwarfs/os_access.h>
#include <dwarfs/string.h>
#include <dwarfs/util.h>

#include <dwarfs/internal/worker_group.h>
Expand Down Expand Up @@ -232,16 +232,13 @@ class basic_worker_group final : public worker_group::impl, private Policy {

void check_set_affinity_from_enviroment(const char* group_name) {
if (auto var = os_.getenv("DWARFS_WORKER_GROUP_AFFINITY")) {
std::vector<std::string_view> groups;
folly::split(':', var.value(), groups);
auto groups = split_to<std::vector<std::string_view>>(var.value(), ':');

for (auto& group : groups) {
std::vector<std::string_view> parts;
folly::split('=', group, parts);
auto parts = split_to<std::vector<std::string_view>>(group, '=');

if (parts.size() == 2 && parts[0] == group_name) {
std::vector<int> cpus;
folly::split(',', parts[1], cpus);
auto cpus = split_to<std::vector<int>>(parts[1], ',');
set_affinity(cpus);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include <stdexcept>

#include <folly/Conv.h>
#include <folly/String.h>
#include <folly/small_vector.h>

#include <dwarfs/config.h>
Expand All @@ -42,6 +41,7 @@
#include <fmt/format.h>

#include <dwarfs/logger.h>
#include <dwarfs/string.h>
#include <dwarfs/terminal_ansi.h>
#include <dwarfs/util.h>

Expand Down Expand Up @@ -189,7 +189,7 @@ void stream_logger::write(level_type level, const std::string& output,
color_ ? folly::symbolizer::SymbolizePrinter::COLOR : 0);
printer.println(addresses, 3);
stacktrace = printer.str();
folly::split('\n', stacktrace, st_lines);
split_to(stacktrace, '\n', st_lines);
if (st_lines.back().empty()) {
st_lines.pop_back();
}
Expand Down Expand Up @@ -217,9 +217,9 @@ void stream_logger::write(level_type level, const std::string& output,
tmp.reserve(output.size());
std::copy_if(output.begin(), output.end(), std::back_inserter(tmp),
[](char c) { return c != '\r'; });
folly::split('\n', tmp, lines);
split_to(tmp, '\n', lines);
} else {
folly::split('\n', output, lines);
split_to(output, '\n', lines);
}

if (lines.back().empty()) {
Expand Down
6 changes: 2 additions & 4 deletions src/option_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,15 @@
#include <fmt/ranges.h>
#endif

#include <folly/String.h>

#include <dwarfs/error.h>
#include <dwarfs/option_map.h>
#include <dwarfs/string.h>
#include <dwarfs/util.h>

namespace dwarfs {

option_map::option_map(const std::string_view spec) {
std::vector<std::string_view> arg;
folly::split(':', spec, arg);
auto arg = split_to<std::vector<std::string_view>>(spec, ':');

choice_ = arg[0];

Expand Down
6 changes: 2 additions & 4 deletions src/writer/category_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@

#include <fmt/format.h>

#include <folly/String.h>

#include <dwarfs/string.h>
#include <dwarfs/writer/category_parser.h>
#include <dwarfs/writer/category_resolver.h>

Expand All @@ -40,9 +39,8 @@ category_parser::parse(std::string_view arg) const {
}

std::vector<fragment_category::value_type> rv;
std::vector<std::string_view> categories;
auto categories = split_to<std::vector<std::string_view>>(arg, ',');

folly::split(',', arg, categories);
rv.reserve(categories.size());

for (auto const& name : categories) {
Expand Down
5 changes: 2 additions & 3 deletions src/xattr_posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@

#include <sys/xattr.h>

#include <folly/String.h>

#include <dwarfs/string.h>
#include <dwarfs/xattr.h>

namespace dwarfs {
Expand Down Expand Up @@ -144,7 +143,7 @@ listxattr(std::filesystem::path const& path, std::error_code& ec) {
if (size > 0) {
// drop the last '\0'
list.resize(size - 1);
folly::split('\0', list, names);
split_to(list, '\0', names);
}

return names;
Expand Down
11 changes: 7 additions & 4 deletions test/compat_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <dwarfs/mmap.h>
#include <dwarfs/options.h>
#include <dwarfs/reader/filesystem_v2.h>
#include <dwarfs/string.h>
#include <dwarfs/thread_pool.h>
#include <dwarfs/utility/filesystem_extractor.h>
#include <dwarfs/utility/rewrite_filesystem.h>
Expand Down Expand Up @@ -999,15 +1000,17 @@ void check_compat(logger& lgr, reader::filesystem_v2 const& fs,
}

std::vector<std::string> parts;
folly::split(' ', line, parts);
split_to(line, ' ', parts);
auto name = parts.front().substr(2);
parts.erase(parts.begin());
std::unordered_map<std::string, std::string> kv;

for (auto const& p : parts) {
std::string key, value;
folly::split('=', p, key, value);
kv[key] = value;
auto pos = p.find('=');
if (pos == std::string::npos) {
throw std::runtime_error("unexpected mtree line: " + line);
}
kv[p.substr(0, pos)] = p.substr(pos + 1);
}

++num;
Expand Down

0 comments on commit 6c12a04

Please sign in to comment.