refactor(tvix): Make static strings constexpr string_views
Make all static std::strings constexpr std::string_views, and replace concatenation with absl::StrCat where necessary. Technically all of these are constant, so they really don't need to be top-level statics - and since I'm trying to get rid of as much global state as possible in preparation for making the nix daemon properly multithreaded I figured I'd knock these out while I was at it. Change-Id: Ibd3ad9ef68f0a0eacb135541b39fdb13dae042e1 Reviewed-on: https://cl.tvl.fyi/c/depot/+/1939 Tested-by: BuildkiteCI Reviewed-by: tazjin <mail@tazj.in>
This commit is contained in:
parent
31b06516f3
commit
381ce8a666
8 changed files with 46 additions and 42 deletions
23
third_party/nix/src/libstore/ssh-store.cc
vendored
23
third_party/nix/src/libstore/ssh-store.cc
vendored
|
|
@ -1,3 +1,5 @@
|
|||
#include <absl/strings/str_cat.h>
|
||||
|
||||
#include "libstore/remote-fs-accessor.hh"
|
||||
#include "libstore/remote-store.hh"
|
||||
#include "libstore/ssh.hh"
|
||||
|
|
@ -8,7 +10,7 @@
|
|||
|
||||
namespace nix {
|
||||
|
||||
static std::string uriScheme = "ssh-ng://";
|
||||
constexpr std::string_view kUriScheme = "ssh-ng://";
|
||||
|
||||
class SSHStore : public RemoteStore {
|
||||
public:
|
||||
|
|
@ -25,7 +27,7 @@ class SSHStore : public RemoteStore {
|
|||
// Use SSH master only if using more than 1 connection.
|
||||
connections->capacity() > 1, compress) {}
|
||||
|
||||
std::string getUri() override { return uriScheme + host; }
|
||||
std::string getUri() override { return absl::StrCat(kUriScheme, host); }
|
||||
|
||||
bool sameMachine() override { return false; }
|
||||
|
||||
|
|
@ -74,13 +76,14 @@ ref<RemoteStore::Connection> SSHStore::openConnection() {
|
|||
return conn;
|
||||
}
|
||||
|
||||
static RegisterStoreImplementation regStore([](const std::string& uri,
|
||||
const Store::Params& params)
|
||||
-> std::shared_ptr<Store> {
|
||||
if (std::string(uri, 0, uriScheme.size()) != uriScheme) {
|
||||
return nullptr;
|
||||
}
|
||||
return std::make_shared<SSHStore>(std::string(uri, uriScheme.size()), params);
|
||||
});
|
||||
static RegisterStoreImplementation regStore(
|
||||
[](const std::string& uri,
|
||||
const Store::Params& params) -> std::shared_ptr<Store> {
|
||||
if (std::string(uri, 0, kUriScheme.size()) != kUriScheme) {
|
||||
return nullptr;
|
||||
}
|
||||
return std::make_shared<SSHStore>(std::string(uri, kUriScheme.size()),
|
||||
params);
|
||||
});
|
||||
|
||||
} // namespace nix
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue