Skip to content

Commit

Permalink
hash.cc/hash.h: Minor C++ improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
kolloch committed Nov 25, 2023
1 parent 2135947 commit d53e461
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions src/libutil/hash.hh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ struct Hash
/**
* Create a zero-filled hash object.
*/
Hash(HashType type);
explicit Hash(HashType type);

/**
* Parse the hash from a string representation in the format
Expand Down Expand Up @@ -103,23 +103,23 @@ public:
/**
* Returns the length of a base-16 representation of this hash.
*/
size_t base16Len() const
[[nodiscard]] size_t base16Len() const
{
return hashSize * 2;
}

/**
* Returns the length of a base-32 representation of this hash.
*/
size_t base32Len() const
[[nodiscard]] size_t base32Len() const
{
return (hashSize * 8 - 1) / 5 + 1;
}

/**
* Returns the length of a base-64 representation of this hash.
*/
size_t base64Len() const
[[nodiscard]] size_t base64Len() const
{
return ((4 * hashSize / 3) + 3) & ~3;
}
Expand All @@ -129,14 +129,14 @@ public:
* or base-64. By default, this is prefixed by the hash type
* (e.g. "sha256:").
*/
std::string to_string(HashFormat hashFormat, bool includeType) const;
[[nodiscard]] std::string to_string(HashFormat hashFormat, bool includeType) const;

std::string gitRev() const
[[nodiscard]] std::string gitRev() const
{
return to_string(HashFormat::Base16, false);
}

std::string gitShortRev() const
[[nodiscard]] std::string gitShortRev() const
{
return std::string(to_string(HashFormat::Base16, false), 0, 7);
}
Expand Down
2 changes: 1 addition & 1 deletion src/nix/hash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct CmdHashBase : Command
std::vector<std::string> paths;
std::optional<std::string> modulus;

CmdHashBase(FileIngestionMethod mode) : mode(mode)
explicit CmdHashBase(FileIngestionMethod mode) : mode(mode)
{
addFlag({
.longName = "sri",
Expand Down

0 comments on commit d53e461

Please sign in to comment.