Fix consts and casts

This commit is contained in:
Jacek Galowicz 2023-11-07 13:40:21 +01:00
parent c581143e0c
commit df8bfe84cc
6 changed files with 14 additions and 14 deletions

View File

@ -161,7 +161,7 @@ struct NarAccessor : public SourceAccessor
{
NarMember * current = &root;
for (auto & i : path) {
for (const auto & i : path) {
if (current->stat.type != Type::tDirectory) return nullptr;
auto child = current->children.find(std::string(i));
if (child == current->children.end()) return nullptr;
@ -194,7 +194,7 @@ struct NarAccessor : public SourceAccessor
throw Error("path '%1%' inside NAR file is not a directory", path);
DirEntries res;
for (auto & child : i.children)
for (const auto & child : i.children)
res.insert_or_assign(child.first, std::nullopt);
return res;
@ -259,7 +259,7 @@ json listNar(ref<SourceAccessor> accessor, const CanonPath & path, bool recurse)
{
obj["entries"] = json::object();
json &res2 = obj["entries"];
for (auto & [name, type] : accessor->readDirectory(path)) {
for (const auto & [name, type] : accessor->readDirectory(path)) {
if (recurse) {
res2[name] = listNar(accessor, path + name, true);
} else

View File

@ -25,7 +25,7 @@ ref<SourceAccessor> makeNarAccessor(Source & source);
* readFile() method of the accessor to get the contents of files
* inside the NAR.
*/
typedef std::function<std::string(uint64_t, uint64_t)> GetNarBytes;
using GetNarBytes = std::function<std::string(uint64_t, uint64_t)>;
ref<SourceAccessor> makeLazyNarAccessor(
const std::string & listing,

View File

@ -38,12 +38,12 @@ NarInfo::NarInfo(const Store & store, const std::string & s, const std::string &
while (pos < s.size()) {
size_t colon = s.find(':', pos);
if (colon == std::string::npos) throw corrupt("expecting ':'");
if (colon == s.npos) throw corrupt("expecting ':'");
std::string name(s, pos, colon - pos);
size_t eol = s.find('\n', colon + 2);
if (eol == std::string::npos) throw corrupt("expecting '\\n'");
if (eol == s.npos) throw corrupt("expecting '\\n'");
std::string value(s, colon + 2, eol - colon - 2);

View File

@ -17,10 +17,10 @@ struct NarInfo : ValidPathInfo
uint64_t fileSize = 0;
NarInfo() = delete;
NarInfo(const Store & store, std::string && name, ContentAddressWithReferences && ca, Hash narHash)
NarInfo(const Store & store, std::string name, ContentAddressWithReferences ca, Hash narHash)
: ValidPathInfo(store, std::move(name), std::move(ca), narHash)
{ }
NarInfo(StorePath && path, Hash narHash) : ValidPathInfo(std::move(path), narHash) { }
NarInfo(StorePath path, Hash narHash) : ValidPathInfo(std::move(path), narHash) { }
NarInfo(const ValidPathInfo & info) : ValidPathInfo(info) { }
NarInfo(const Store & store, const std::string & s, const std::string & whence);

View File

@ -31,14 +31,14 @@ std::optional<TrustedFlag> WorkerProto::Serialise<std::optional<TrustedFlag>>::r
void WorkerProto::Serialise<std::optional<TrustedFlag>>::write(const Store & store, WorkerProto::WriteConn conn, const std::optional<TrustedFlag> & optTrusted)
{
if (!optTrusted)
conn.to << (uint8_t)0;
conn.to << uint8_t{0};
else {
switch (*optTrusted) {
case Trusted:
conn.to << (uint8_t)1;
conn.to << uint8_t{1};
break;
case NotTrusted:
conn.to << (uint8_t)2;
conn.to << uint8_t{2};
break;
default:
assert(false);
@ -101,7 +101,7 @@ void WorkerProto::Serialise<KeyedBuildResult>::write(const Store & store, Worker
BuildResult WorkerProto::Serialise<BuildResult>::read(const Store & store, WorkerProto::ReadConn conn)
{
BuildResult res;
res.status = (BuildResult::Status) readInt(conn.from);
res.status = static_cast<BuildResult::Status>(readInt(conn.from));
conn.from >> res.errorMsg;
if (GET_PROTOCOL_MINOR(conn.version) >= 29) {
conn.from

View File

@ -171,7 +171,7 @@ enum struct WorkerProto::Op : uint64_t
*/
inline Sink & operator << (Sink & sink, WorkerProto::Op op)
{
return sink << (uint64_t) op;
return sink << static_cast<uint64_t>(op);
}
/**
@ -181,7 +181,7 @@ inline Sink & operator << (Sink & sink, WorkerProto::Op op)
*/
inline std::ostream & operator << (std::ostream & s, WorkerProto::Op op)
{
return s << (uint64_t) op;
return s << static_cast<uint64_t>(op);
}
/**