Skip to content

Commit 5915fe3

Browse files
committed
Revert "Use shared pointers in the memory source accessor"
This is no longer necessary. This reverts commit 4df60e6.
1 parent c4c92c4 commit 5915fe3

File tree

3 files changed

+15
-23
lines changed

3 files changed

+15
-23
lines changed

src/libutil-tests/git.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -233,30 +233,30 @@ TEST_F(GitTest, both_roundrip)
233233
.contents{
234234
{
235235
"foo",
236-
make_ref<File>(File::Regular{
236+
File::Regular{
237237
.contents = "hello\n\0\n\tworld!",
238-
}),
238+
},
239239
},
240240
{
241241
"bar",
242-
make_ref<File>(File::Directory{
242+
File::Directory{
243243
.contents =
244244
{
245245
{
246246
"baz",
247-
make_ref<File>(File::Regular{
247+
File::Regular{
248248
.executable = true,
249249
.contents = "good day,\n\0\n\tworld!",
250-
}),
250+
},
251251
},
252252
{
253253
"quux",
254-
make_ref<File>(File::Symlink{
254+
File::Symlink{
255255
.target = "/over/there",
256-
}),
256+
},
257257
},
258258
},
259-
}),
259+
},
260260
},
261261
},
262262
};

src/libutil/include/nix/util/memory-source-accessor.hh

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ struct MemorySourceAccessor : virtual SourceAccessor
3535
{
3636
using Name = std::string;
3737

38-
std::map<Name, ref<File>, std::less<>> contents;
38+
std::map<Name, File, std::less<>> contents;
3939

4040
bool operator==(const Directory &) const noexcept;
4141
// TODO libc++ 16 (used by darwin) missing `std::map::operator <=>`, can't do yet.
@@ -89,21 +89,13 @@ struct MemorySourceAccessor : virtual SourceAccessor
8989
SourcePath addFile(CanonPath path, std::string && contents);
9090
};
9191

92-
inline bool
93-
MemorySourceAccessor::File::Directory::operator==(const MemorySourceAccessor::File::Directory & other) const noexcept
94-
{
95-
return std::ranges::equal(contents, other.contents, [](const auto & lhs, const auto & rhs) -> bool {
96-
return lhs.first == rhs.first && *lhs.second == *rhs.second;
97-
});
98-
};
92+
inline bool MemorySourceAccessor::File::Directory::operator==(
93+
const MemorySourceAccessor::File::Directory &) const noexcept = default;
9994

10095
inline bool
10196
MemorySourceAccessor::File::Directory::operator<(const MemorySourceAccessor::File::Directory & other) const noexcept
10297
{
103-
return std::ranges::lexicographical_compare(
104-
contents, other.contents, [](const auto & lhs, const auto & rhs) -> bool {
105-
return lhs.first < rhs.first && *lhs.second < *rhs.second;
106-
});
98+
return contents < other.contents;
10799
}
108100

109101
inline bool MemorySourceAccessor::File::operator==(const MemorySourceAccessor::File &) const noexcept = default;

src/libutil/memory-source-accessor.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ MemorySourceAccessor::File * MemorySourceAccessor::open(const CanonPath & path,
3939
i,
4040
{
4141
std::string{name},
42-
make_ref<File>(File::Directory{}),
42+
File::Directory{},
4343
});
4444
}
4545
}
46-
cur = &*i->second;
46+
cur = &i->second;
4747
}
4848

4949
if (newF && create)
@@ -107,7 +107,7 @@ MemorySourceAccessor::DirEntries MemorySourceAccessor::readDirectory(const Canon
107107
if (auto * d = std::get_if<File::Directory>(&f->raw)) {
108108
DirEntries res;
109109
for (auto & [name, file] : d->contents)
110-
res.insert_or_assign(name, file->lstat().type);
110+
res.insert_or_assign(name, file.lstat().type);
111111
return res;
112112
} else
113113
throw Error("file '%s' is not a directory", path);

0 commit comments

Comments
 (0)