1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-15 23:12:44 +01:00

libutil: Use std::shared_ptr<const Pos> instead of std::shared_ptr<Pos>

There's actually no mutation happening so there's no point in using
a mutable shared_ptr. Furthermore, this makes it much more evident to
the reader that no actual mutation (especially in multithreaded case)
is happening.

Also get rid of redundant constructor that isn't actually used anywhere
other than `Pos::operator std::shared_ptr<Pos>` which just passes in &*this,
(identical to just `this`), which can't be nullptr.
This commit is contained in:
Sergei Zimmerman 2025-06-01 20:55:16 +00:00
parent 587b5f5361
commit b73e706589
No known key found for this signature in database
GPG key ID: A9B0B557CA632325
5 changed files with 11 additions and 23 deletions

View file

@ -2,19 +2,9 @@
namespace nix {
Pos::Pos(const Pos * other)
Pos::operator std::shared_ptr<const Pos>() const
{
if (!other) {
return;
}
line = other->line;
column = other->column;
origin = other->origin;
}
Pos::operator std::shared_ptr<Pos>() const
{
return std::make_shared<Pos>(&*this);
return std::make_shared<const Pos>(*this);
}
std::optional<LinesOfCode> Pos::getCodeLines() const