From 5915fe319011b4be8accb2e3e4a21e9e2000d7db Mon Sep 17 00:00:00 2001 From: Sergei Zimmerman Date: Mon, 22 Sep 2025 01:17:00 +0300 Subject: [PATCH] Revert "Use shared pointers in the memory source accessor" This is no longer necessary. This reverts commit 4df60e639b7e492ac5f651f2b3aa02055de5549a. --- src/libutil-tests/git.cc | 16 ++++++++-------- .../include/nix/util/memory-source-accessor.hh | 16 ++++------------ src/libutil/memory-source-accessor.cc | 6 +++--- 3 files changed, 15 insertions(+), 23 deletions(-) diff --git a/src/libutil-tests/git.cc b/src/libutil-tests/git.cc index a06c5896d..6180a4cfc 100644 --- a/src/libutil-tests/git.cc +++ b/src/libutil-tests/git.cc @@ -233,30 +233,30 @@ TEST_F(GitTest, both_roundrip) .contents{ { "foo", - make_ref(File::Regular{ + File::Regular{ .contents = "hello\n\0\n\tworld!", - }), + }, }, { "bar", - make_ref(File::Directory{ + File::Directory{ .contents = { { "baz", - make_ref(File::Regular{ + File::Regular{ .executable = true, .contents = "good day,\n\0\n\tworld!", - }), + }, }, { "quux", - make_ref(File::Symlink{ + File::Symlink{ .target = "/over/there", - }), + }, }, }, - }), + }, }, }, }; diff --git a/src/libutil/include/nix/util/memory-source-accessor.hh b/src/libutil/include/nix/util/memory-source-accessor.hh index 53f1b0241..eba282fe1 100644 --- a/src/libutil/include/nix/util/memory-source-accessor.hh +++ b/src/libutil/include/nix/util/memory-source-accessor.hh @@ -35,7 +35,7 @@ struct MemorySourceAccessor : virtual SourceAccessor { using Name = std::string; - std::map, std::less<>> contents; + std::map> contents; bool operator==(const Directory &) const noexcept; // TODO libc++ 16 (used by darwin) missing `std::map::operator <=>`, can't do yet. @@ -89,21 +89,13 @@ struct MemorySourceAccessor : virtual SourceAccessor SourcePath addFile(CanonPath path, std::string && contents); }; -inline bool -MemorySourceAccessor::File::Directory::operator==(const MemorySourceAccessor::File::Directory & other) const noexcept -{ - return std::ranges::equal(contents, other.contents, [](const auto & lhs, const auto & rhs) -> bool { - return lhs.first == rhs.first && *lhs.second == *rhs.second; - }); -}; +inline bool MemorySourceAccessor::File::Directory::operator==( + const MemorySourceAccessor::File::Directory &) const noexcept = default; inline bool MemorySourceAccessor::File::Directory::operator<(const MemorySourceAccessor::File::Directory & other) const noexcept { - return std::ranges::lexicographical_compare( - contents, other.contents, [](const auto & lhs, const auto & rhs) -> bool { - return lhs.first < rhs.first && *lhs.second < *rhs.second; - }); + return contents < other.contents; } inline bool MemorySourceAccessor::File::operator==(const MemorySourceAccessor::File &) const noexcept = default; diff --git a/src/libutil/memory-source-accessor.cc b/src/libutil/memory-source-accessor.cc index 7d53d6785..caff5b56a 100644 --- a/src/libutil/memory-source-accessor.cc +++ b/src/libutil/memory-source-accessor.cc @@ -39,11 +39,11 @@ MemorySourceAccessor::File * MemorySourceAccessor::open(const CanonPath & path, i, { std::string{name}, - make_ref(File::Directory{}), + File::Directory{}, }); } } - cur = &*i->second; + cur = &i->second; } if (newF && create) @@ -107,7 +107,7 @@ MemorySourceAccessor::DirEntries MemorySourceAccessor::readDirectory(const Canon if (auto * d = std::get_if(&f->raw)) { DirEntries res; for (auto & [name, file] : d->contents) - res.insert_or_assign(name, file->lstat().type); + res.insert_or_assign(name, file.lstat().type); return res; } else throw Error("file '%s' is not a directory", path);