From: Joel Rosdahl Date: Sat, 20 Jan 2024 14:04:03 +0000 (+0100) Subject: perf: Remove now unnecessary fs::path::string calls X-Git-Tag: v4.10~117 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a5cfc7f9012fcf0e3ef6e31f857a85715fad35cb;p=thirdparty%2Fccache.git perf: Remove now unnecessary fs::path::string calls --- diff --git a/src/core/FileRecompressor.cpp b/src/core/FileRecompressor.cpp index da66dc306..c2dedf840 100644 --- a/src/core/FileRecompressor.cpp +++ b/src/core/FileRecompressor.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2022-2023 Joel Rosdahl and other contributors +// Copyright (C) 2022-2024 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -34,7 +34,7 @@ FileRecompressor::recompress(const DirEntry& dir_entry, std::optional level, KeepAtime keep_atime) { - core::CacheEntry::Header header(dir_entry.path().string()); + core::CacheEntry::Header header(dir_entry.path()); const int8_t wanted_level = level ? (*level == 0 ? core::CacheEntry::default_compression_level : *level) @@ -44,8 +44,8 @@ FileRecompressor::recompress(const DirEntry& dir_entry, if (header.compression_level != wanted_level) { const auto cache_file_data = util::value_or_throw( - util::read_file(dir_entry.path().string()), - FMT("Failed to read {}: ", dir_entry.path().string())); + util::read_file(dir_entry.path()), + FMT("Failed to read {}: ", dir_entry.path())); core::CacheEntry cache_entry(cache_file_data); cache_entry.verify_checksum(); @@ -54,19 +54,17 @@ FileRecompressor::recompress(const DirEntry& dir_entry, level ? core::CompressionType::zstd : core::CompressionType::none; header.compression_level = wanted_level; - AtomicFile new_cache_file(dir_entry.path().string(), - AtomicFile::Mode::binary); + AtomicFile new_cache_file(dir_entry.path(), AtomicFile::Mode::binary); new_cache_file.write( core::CacheEntry::serialize(header, cache_entry.payload())); new_cache_file.commit(); - new_dir_entry = - DirEntry(dir_entry.path().string(), DirEntry::LogOnError::yes); + new_dir_entry = DirEntry(dir_entry.path(), DirEntry::LogOnError::yes); } // Restore mtime/atime to keep cache LRU cleanup working as expected: if (keep_atime == KeepAtime::yes || new_dir_entry) { util::set_timestamps( - dir_entry.path().string(), dir_entry.mtime(), dir_entry.atime()); + dir_entry.path(), dir_entry.mtime(), dir_entry.atime()); } m_content_size += util::likely_size_on_disk(header.entry_size); diff --git a/src/core/mainoptions.cpp b/src/core/mainoptions.cpp index 37d45fee3..6824ebd17 100644 --- a/src/core/mainoptions.cpp +++ b/src/core/mainoptions.cpp @@ -377,7 +377,7 @@ trim_dir(const std::string& dir, if (final_size <= trim_max_size) { break; } - if (util::remove(file.path().string())) { + if (util::remove(file.path())) { ++removed_files; final_size -= file.size_on_disk(); } diff --git a/src/storage/local/LocalStorage.cpp b/src/storage/local/LocalStorage.cpp index 65d1615f6..fc6f06804 100644 --- a/src/storage/local/LocalStorage.cpp +++ b/src/storage/local/LocalStorage.cpp @@ -222,10 +222,10 @@ delete_file(const DirEntry& dir_entry, uint64_t& files_in_cache) { const auto result = - util::remove_nfs_safe(dir_entry.path().string(), util::LogFailure::no); + util::remove_nfs_safe(dir_entry.path(), util::LogFailure::no); if (!result && result.error().value() != ENOENT && result.error().value() != ESTALE) { - LOG("Failed to unlink {} ({})", dir_entry.path().string(), strerror(errno)); + LOG("Failed to unlink {} ({})", dir_entry.path(), strerror(errno)); } else { // The counters are intentionally subtracted even if there was no file to // delete since the final cache size calculation will be incorrect if they @@ -390,7 +390,7 @@ clean_dir( if (namespace_) { try { - core::CacheEntry::Header header(file.path().string()); + core::CacheEntry::Header header(file.path()); if (header.namespace_ != *namespace_) { continue; } @@ -824,7 +824,7 @@ LocalStorage::wipe_all(const ProgressReceiver& progress_receiver) l2_progress_receiver(0.5); for (size_t i = 0; i < files.size(); ++i) { - util::remove_nfs_safe(files[i].path().string()); + util::remove_nfs_safe(files[i].path()); l2_progress_receiver(0.5 + 0.5 * ratio(i, files.size())); } @@ -856,7 +856,7 @@ LocalStorage::get_compression_statistics( for (size_t i = 0; i < files.size(); ++i) { const auto& cache_file = files[i]; try { - core::CacheEntry::Header header(cache_file.path().string()); + core::CacheEntry::Header header(cache_file.path()); cs.actual_size += cache_file.size_on_disk(); cs.content_size += util::likely_size_on_disk(header.entry_size); } catch (core::Error&) {