From e44519b75bb26ea02c00c7f67b2193ebc9f22ac9 Mon Sep 17 00:00:00 2001 From: Marcus Holland-Moritz Date: Sun, 22 Nov 2020 14:11:38 +0100 Subject: [PATCH] folly::StringPiece -> std::string_view --- include/dwarfs/entry.h | 5 ++-- include/dwarfs/hash_util.h | 40 ++++++++++++++++++++++++++++++++ include/dwarfs/metadata_writer.h | 5 ++-- src/dwarfs/entry.cpp | 4 ++-- src/dwarfs/scanner.cpp | 16 ++++++------- 5 files changed, 54 insertions(+), 16 deletions(-) create mode 100644 include/dwarfs/hash_util.h diff --git a/include/dwarfs/entry.h b/include/dwarfs/entry.h index 7dc63eeb..fa9245e4 100644 --- a/include/dwarfs/entry.h +++ b/include/dwarfs/entry.h @@ -24,12 +24,11 @@ #include #include #include +#include #include #include -#include - #include "file_interface.h" #include "fstypes.h" @@ -95,7 +94,7 @@ class file : public entry { , with_similarity_(with_similarity) {} type_t type() const override; - folly::StringPiece hash() const; + std::string_view hash() const; void set_inode(std::shared_ptr ino); std::shared_ptr get_inode() const; void accept(entry_visitor& v, bool preorder) override; diff --git a/include/dwarfs/hash_util.h b/include/dwarfs/hash_util.h new file mode 100644 index 00000000..cabdbe4f --- /dev/null +++ b/include/dwarfs/hash_util.h @@ -0,0 +1,40 @@ +/* vim:set ts=2 sw=2 sts=2 et: */ +/** + * \author Marcus Holland-Moritz (github@mhxnet.de) + * \copyright Copyright (c) Marcus Holland-Moritz + * + * This file is part of dwarfs. + * + * dwarfs is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * dwarfs is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with dwarfs. If not, see . + */ + +#pragma once + +#include + +#include + +namespace folly { + +template <> +struct hasher { + using folly_is_avalanching = std::true_type; + + size_t operator()(std::string_view r) const { + return static_cast( + hash::SpookyHashV2::Hash64(r.data(), r.size(), 0)); + } +}; + +} diff --git a/include/dwarfs/metadata_writer.h b/include/dwarfs/metadata_writer.h index bc6f08ee..a694718b 100644 --- a/include/dwarfs/metadata_writer.h +++ b/include/dwarfs/metadata_writer.h @@ -21,10 +21,9 @@ #pragma once +#include #include -#include - #include "fstypes.h" #include "logger.h" @@ -82,7 +81,7 @@ class metadata_writer { } } - void write(folly::StringPiece str) { + void write(std::string_view str) { if (!str.empty()) { write(str.data(), str.size()); } diff --git a/src/dwarfs/entry.cpp b/src/dwarfs/entry.cpp index 3500c0ed..303be74a 100644 --- a/src/dwarfs/entry.cpp +++ b/src/dwarfs/entry.cpp @@ -158,8 +158,8 @@ void entry::pack(dir_entry_ug_time& de) const { entry::type_t file::type() const { return E_FILE; } -folly::StringPiece file::hash() const { - return folly::StringPiece(hash_.begin(), hash_.end()); +std::string_view file::hash() const { + return std::string_view(&hash_[0], hash_.size()); } void file::set_inode(std::shared_ptr ino) { diff --git a/src/dwarfs/scanner.cpp b/src/dwarfs/scanner.cpp index d15e3a52..b1a7e7a9 100644 --- a/src/dwarfs/scanner.cpp +++ b/src/dwarfs/scanner.cpp @@ -34,7 +34,6 @@ #include #include -#include #include #include @@ -46,6 +45,7 @@ #include "dwarfs/entry.h" #include "dwarfs/filesystem_writer.h" #include "dwarfs/fstypes.h" +#include "dwarfs/hash_util.h" #include "dwarfs/inode_manager.h" #include "dwarfs/logger.h" #include "dwarfs/metadata.h" @@ -85,9 +85,9 @@ class scanner_ : public scanner::impl { // TODO: StringPiece? // TODO: Use dense/unordered maps/sets and sort later? using file_name_table_t = - fast_hash_map>; + fast_hash_map>; - std::unordered_map + std::unordered_map compress_names_table(metadata_writer& mw, const file_name_table_t& file_name) const; @@ -118,7 +118,7 @@ scanner_::scanner_(logger& lgr, worker_group& wg, , log_(lgr) {} template -std::unordered_map +std::unordered_map scanner_::compress_names_table( metadata_writer& mw, const file_name_table_t& file_name) const { log_.info() << "compressing names table..."; @@ -130,7 +130,7 @@ scanner_::compress_names_table( index.set_empty_key(0); uint32_t index_pos = 0; - std::unordered_map offset; + std::unordered_map offset; size_t saved = 0; size_t orig_offset = mw.offset(); @@ -142,7 +142,7 @@ scanner_::compress_names_table( for (auto size : sizes) { auto nsi = file_name.find(size); assert(nsi != file_name.end()); - std::vector names(nsi->second.size()); + std::vector names(nsi->second.size()); std::copy(nsi->second.begin(), nsi->second.end(), names.begin()); std::sort(names.begin(), names.end()); @@ -250,7 +250,7 @@ class save_links_visitor : public entry_visitor { private: metadata_writer& mw_; - std::unordered_map offset_; + std::unordered_map offset_; }; class save_directories_visitor : public entry_visitor { @@ -374,7 +374,7 @@ void scanner_::scan(filesystem_writer& fsw, wg_.wait(); size_t total{0}; - std::unordered_map, folly::Hash> + std::unordered_map, folly::Hash> file_hash; file_name_table_t file_name;