1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-05 12:21:48 +02:00

Merge pull request #11682 from NaN-git/opt-str

Remove superfluous `std::string` copy operations
This commit is contained in:
Robert Hensing 2024-10-12 10:59:40 +02:00 committed by GitHub
commit 30c4f5eb51
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 72 additions and 54 deletions

View file

@ -293,7 +293,7 @@ void RootArgs::parseCmdline(const Strings & _cmdline, bool allowShebang)
// We match one space after `nix` so that we preserve indentation.
// No space is necessary for an empty line. An empty line has basically no effect.
if (std::regex_match(line, match, std::regex("^#!\\s*nix(:? |$)(.*)$")))
shebangContent += match[2].str() + "\n";
shebangContent += std::string_view{match[2].first, match[2].second} + "\n";
}
for (const auto & word : parseShebangContent(shebangContent)) {
cmdline.push_back(word);

View file

@ -85,10 +85,10 @@ public:
void logEI(const ErrorInfo & ei) override
{
std::stringstream oss;
std::ostringstream oss;
showErrorInfo(oss, ei, loggerSettings.showTrace.get());
log(ei.level, oss.str());
log(ei.level, toView(oss));
}
void startActivity(ActivityId act, Verbosity lvl, ActivityType type,

View file

@ -6,6 +6,21 @@
namespace nix {
struct view_stringbuf : public std::stringbuf
{
inline std::string_view toView()
{
auto begin = pbase();
return {begin, begin + pubseekoff(0, std::ios_base::cur, std::ios_base::out)};
}
};
std::string_view toView(const std::ostringstream & os)
{
auto buf = static_cast<view_stringbuf *>(os.rdbuf());
return buf->toView();
}
template std::list<std::string> tokenizeString(std::string_view s, std::string_view separators);
template std::set<std::string> tokenizeString(std::string_view s, std::string_view separators);
template std::vector<std::string> tokenizeString(std::string_view s, std::string_view separators);

View file

@ -8,6 +8,11 @@
namespace nix {
/*
* workaround for unavailable view() method (C++20) of std::ostringstream under MacOS with clang-16
*/
std::string_view toView(const std::ostringstream & os);
/**
* String tokenizer.
*