From 65967bbbb163d7955de412381831c52c14ce1dbc Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Mon, 7 Sep 2020 13:18:18 -0400 Subject: refactor(tvix): Convert refLength to constexpr This is constant, so let's make it a constexpr. Change-Id: I6a9eb9f740979740f730ebe142d2cbf23dbcfd70 Reviewed-on: https://cl.tvl.fyi/c/depot/+/1961 Tested-by: BuildkiteCI Reviewed-by: kanepyork --- third_party/nix/src/libstore/references.cc | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/third_party/nix/src/libstore/references.cc b/third_party/nix/src/libstore/references.cc index b70d282e8df8..f120439c1060 100644 --- a/third_party/nix/src/libstore/references.cc +++ b/third_party/nix/src/libstore/references.cc @@ -11,7 +11,7 @@ namespace nix { -static unsigned int refLength = 32; /* characters */ +constexpr unsigned int kRefLength = 32; /* characters */ static void search(const unsigned char* s, size_t len, StringSet& hashes, StringSet& seen) { @@ -27,10 +27,10 @@ static void search(const unsigned char* s, size_t len, StringSet& hashes, initialised = true; } - for (size_t i = 0; i + refLength <= len;) { + for (size_t i = 0; i + kRefLength <= len;) { int j = 0; bool match = true; - for (j = refLength - 1; j >= 0; --j) { + for (j = kRefLength - 1; j >= 0; --j) { if (!isBase32[s[i + j]]) { i += j + 1; match = false; @@ -40,7 +40,7 @@ static void search(const unsigned char* s, size_t len, StringSet& hashes, if (!match) { continue; } - std::string ref(reinterpret_cast(s) + i, refLength); + std::string ref(reinterpret_cast(s) + i, kRefLength); if (hashes.find(ref) != hashes.end()) { DLOG(INFO) << "found reference to '" << ref << "' at offset " << i; seen.insert(ref); @@ -69,17 +69,17 @@ void RefScanSink::operator()(const unsigned char* data, size_t len) { fragment, so search in the concatenation of the tail of the previous fragment and the start of the current fragment. */ std::string s = tail + std::string(reinterpret_cast(data), - len > refLength ? refLength : len); + len > kRefLength ? kRefLength : len); search(reinterpret_cast(s.data()), s.size(), hashes, seen); search(data, len, hashes, seen); - size_t tailLen = len <= refLength ? len : refLength; + size_t tailLen = len <= kRefLength ? len : kRefLength; tail = - std::string(tail, tail.size() < refLength - tailLen + std::string(tail, tail.size() < kRefLength - tailLen ? 0 - : tail.size() - (refLength - tailLen)) + + : tail.size() - (kRefLength - tailLen)) + std::string(reinterpret_cast(data) + len - tailLen, tailLen); } @@ -98,7 +98,7 @@ PathSet scanForReferences(const std::string& path, const PathSet& refs, throw Error(format("bad reference '%1%'") % i); } std::string s = std::string(baseName, 0, pos); - assert(s.size() == refLength); + assert(s.size() == kRefLength); assert(backMap.find(s) == backMap.end()); // parseHash(htSHA256, s); sink.hashes.insert(s); -- cgit 1.4.1