mirror of
https://github.com/NixOS/nix.git
synced 2025-11-25 11:49:35 +01:00
Apply clang-format universally.
* It is tough to contribute to a project that doesn't use a formatter, * It is extra hard to contribute to a project which has configured the formatter, but ignores it for some files * Code formatting makes it harder to hide obscure / weird bugs by accident or on purpose, Let's rip the bandaid off? Note that PRs currently in flight should be able to be merged relatively easily by applying `clang-format` to their tip prior to merge. Co-authored-by: Graham Christensen <graham@grahamc.com>
This commit is contained in:
parent
9b8b5d8560
commit
95d9c13716
585 changed files with 23297 additions and 23164 deletions
|
|
@ -7,27 +7,22 @@
|
|||
#include <mutex>
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
namespace nix {
|
||||
|
||||
|
||||
static size_t refLength = 32; /* characters */
|
||||
|
||||
|
||||
static void search(
|
||||
std::string_view s,
|
||||
StringSet & hashes,
|
||||
StringSet & seen)
|
||||
static void search(std::string_view s, StringSet & hashes, StringSet & seen)
|
||||
{
|
||||
static std::once_flag initialised;
|
||||
static bool isBase32[256];
|
||||
std::call_once(initialised, [](){
|
||||
for (unsigned int i = 0; i < 256; ++i) isBase32[i] = false;
|
||||
std::call_once(initialised, []() {
|
||||
for (unsigned int i = 0; i < 256; ++i)
|
||||
isBase32[i] = false;
|
||||
for (unsigned int i = 0; i < nix32Chars.size(); ++i)
|
||||
isBase32[(unsigned char) nix32Chars[i]] = true;
|
||||
});
|
||||
|
||||
for (size_t i = 0; i + refLength <= s.size(); ) {
|
||||
for (size_t i = 0; i + refLength <= s.size();) {
|
||||
int j;
|
||||
bool match = true;
|
||||
for (j = refLength - 1; j >= 0; --j)
|
||||
|
|
@ -36,7 +31,8 @@ static void search(
|
|||
match = false;
|
||||
break;
|
||||
}
|
||||
if (!match) continue;
|
||||
if (!match)
|
||||
continue;
|
||||
std::string ref(s.substr(i, refLength));
|
||||
if (hashes.erase(ref)) {
|
||||
debug("found reference to '%1%' at offset '%2%'", ref, i);
|
||||
|
|
@ -46,8 +42,7 @@ static void search(
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void RefScanSink::operator () (std::string_view data)
|
||||
void RefScanSink::operator()(std::string_view data)
|
||||
{
|
||||
/* It's possible that a reference spans the previous and current
|
||||
fragment, so search in the concatenation of the tail of the
|
||||
|
|
@ -65,14 +60,14 @@ void RefScanSink::operator () (std::string_view data)
|
|||
tail.append(data.data() + data.size() - tailLen, tailLen);
|
||||
}
|
||||
|
||||
|
||||
RewritingSink::RewritingSink(const std::string & from, const std::string & to, Sink & nextSink)
|
||||
: RewritingSink({{from, to}}, nextSink)
|
||||
{
|
||||
}
|
||||
|
||||
RewritingSink::RewritingSink(const StringMap & rewrites, Sink & nextSink)
|
||||
: rewrites(rewrites), nextSink(nextSink)
|
||||
: rewrites(rewrites)
|
||||
, nextSink(nextSink)
|
||||
{
|
||||
std::string::size_type maxRewriteSize = 0;
|
||||
for (auto & [from, to] : rewrites) {
|
||||
|
|
@ -82,29 +77,29 @@ RewritingSink::RewritingSink(const StringMap & rewrites, Sink & nextSink)
|
|||
this->maxRewriteSize = maxRewriteSize;
|
||||
}
|
||||
|
||||
void RewritingSink::operator () (std::string_view data)
|
||||
void RewritingSink::operator()(std::string_view data)
|
||||
{
|
||||
std::string s(prev);
|
||||
s.append(data);
|
||||
|
||||
s = rewriteStrings(s, rewrites);
|
||||
|
||||
prev = s.size() < maxRewriteSize
|
||||
? s
|
||||
: maxRewriteSize == 0
|
||||
? ""
|
||||
: std::string(s, s.size() - maxRewriteSize + 1, maxRewriteSize - 1);
|
||||
prev = s.size() < maxRewriteSize ? s
|
||||
: maxRewriteSize == 0 ? ""
|
||||
: std::string(s, s.size() - maxRewriteSize + 1, maxRewriteSize - 1);
|
||||
|
||||
auto consumed = s.size() - prev.size();
|
||||
|
||||
pos += consumed;
|
||||
|
||||
if (consumed) nextSink(s.substr(0, consumed));
|
||||
if (consumed)
|
||||
nextSink(s.substr(0, consumed));
|
||||
}
|
||||
|
||||
void RewritingSink::flush()
|
||||
{
|
||||
if (prev.empty()) return;
|
||||
if (prev.empty())
|
||||
return;
|
||||
pos += prev.size();
|
||||
nextSink(prev);
|
||||
prev.clear();
|
||||
|
|
@ -116,7 +111,7 @@ HashModuloSink::HashModuloSink(HashAlgorithm ha, const std::string & modulus)
|
|||
{
|
||||
}
|
||||
|
||||
void HashModuloSink::operator () (std::string_view data)
|
||||
void HashModuloSink::operator()(std::string_view data)
|
||||
{
|
||||
rewritingSink(data);
|
||||
}
|
||||
|
|
@ -136,4 +131,4 @@ HashResult HashModuloSink::finish()
|
|||
return {h.first, rewritingSink.pos};
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace nix
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue