Merge "Remove 100s of CPU time (10%) from build times (1465s -> 1302s)" into main
This commit is contained in:
commit
18aa3e1d57
18 changed files with 64 additions and 32 deletions
|
@ -22,6 +22,7 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
@ -29,7 +30,6 @@
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
|
|
@ -26,10 +26,9 @@
|
||||||
#pragma clang diagnostic ignored "-Wimplicit-fallthrough"
|
#pragma clang diagnostic ignored "-Wimplicit-fallthrough"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <boost/lexical_cast.hpp>
|
|
||||||
|
|
||||||
#include "nixexpr.hh"
|
#include "nixexpr.hh"
|
||||||
#include "parser-tab.hh"
|
#include "parser-tab.hh"
|
||||||
|
#include "strings.hh"
|
||||||
|
|
||||||
using namespace nix;
|
using namespace nix;
|
||||||
|
|
||||||
|
@ -132,9 +131,10 @@ or { return OR_KW; }
|
||||||
|
|
||||||
{ID} { yylval->id = {yytext, (size_t) yyleng}; return ID; }
|
{ID} { yylval->id = {yytext, (size_t) yyleng}; return ID; }
|
||||||
{INT} { errno = 0;
|
{INT} { errno = 0;
|
||||||
try {
|
std::optional<int64_t> numMay = string2Int<int64_t>(yytext);
|
||||||
yylval->n = boost::lexical_cast<int64_t>(yytext);
|
if (numMay.has_value()) {
|
||||||
} catch (const boost::bad_lexical_cast &) {
|
yylval->n = *numMay;
|
||||||
|
} else {
|
||||||
throw ParseError(ErrorInfo{
|
throw ParseError(ErrorInfo{
|
||||||
.msg = HintFmt("invalid integer '%1%'", yytext),
|
.msg = HintFmt("invalid integer '%1%'", yytext),
|
||||||
.pos = state->positions[CUR_POS],
|
.pos = state->positions[CUR_POS],
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include "escape-string.hh"
|
#include "escape-string.hh"
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <sstream>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <span>
|
#include <span>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
#include "escape-string.hh"
|
#include "escape-string.hh"
|
||||||
#include "print.hh"
|
#include "print.hh"
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
#include <sstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include <future>
|
#include <future>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
|
|
@ -64,10 +64,13 @@ extern "C" int sandbox_init_with_parameters(const char *profile, uint64_t flags,
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
|
namespace {
|
||||||
/**
|
/**
|
||||||
* The system for which Nix is compiled.
|
* The system for which Nix is compiled.
|
||||||
*/
|
*/
|
||||||
constexpr std::string_view nativeSystem = SYSTEM;
|
[[gnu::unused]]
|
||||||
|
constexpr const std::string_view nativeSystem = SYSTEM;
|
||||||
|
}
|
||||||
|
|
||||||
void handleDiffHook(
|
void handleDiffHook(
|
||||||
uid_t uid, uid_t gid,
|
uid_t uid, uid_t gid,
|
||||||
|
|
|
@ -14,6 +14,8 @@
|
||||||
#include "derivations.hh"
|
#include "derivations.hh"
|
||||||
#include "args.hh"
|
#include "args.hh"
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
namespace nix::daemon {
|
namespace nix::daemon {
|
||||||
|
|
||||||
Sink & operator << (Sink & sink, const Logger::Fields & fields)
|
Sink & operator << (Sink & sink, const Logger::Fields & fields)
|
||||||
|
|
|
@ -140,7 +140,7 @@ static Machine parseBuilderLine(const std::string & line)
|
||||||
};
|
};
|
||||||
|
|
||||||
auto parseFloatField = [&](size_t fieldIndex) {
|
auto parseFloatField = [&](size_t fieldIndex) {
|
||||||
const auto result = string2Int<float>(tokens[fieldIndex]);
|
const auto result = string2Float<float>(tokens[fieldIndex]);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
throw FormatError("bad machine specification: failed to convert column #%lu in a row: '%s' to 'float'", fieldIndex, line);
|
throw FormatError("bad machine specification: failed to convert column #%lu in a row: '%s' to 'float'", fieldIndex, line);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "namespaces.hh"
|
#include "namespaces.hh"
|
||||||
#include "signals.hh"
|
#include "signals.hh"
|
||||||
#include "strings.hh"
|
#include "strings.hh"
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
# include <mach-o/dyld.h>
|
# include <mach-o/dyld.h>
|
||||||
|
|
|
@ -13,8 +13,6 @@
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <boost/lexical_cast.hpp>
|
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include "terminal.hh"
|
#include "terminal.hh"
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
#include <sstream>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
|
@ -10,8 +10,6 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
#include <boost/lexical_cast.hpp>
|
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
#include "strings.hh"
|
#include "strings.hh"
|
||||||
|
#include <boost/lexical_cast.hpp>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
|
@ -89,6 +91,43 @@ std::string Rewriter::operator()(std::string s)
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class N>
|
||||||
|
std::optional<N> string2Int(const std::string_view s)
|
||||||
|
{
|
||||||
|
if (s.substr(0, 1) == "-" && !std::numeric_limits<N>::is_signed)
|
||||||
|
return std::nullopt;
|
||||||
|
try {
|
||||||
|
return boost::lexical_cast<N>(s.data(), s.size());
|
||||||
|
} catch (const boost::bad_lexical_cast &) {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Explicitly instantiated in one place for faster compilation
|
||||||
|
template std::optional<unsigned char> string2Int<unsigned char>(const std::string_view s);
|
||||||
|
template std::optional<unsigned short> string2Int<unsigned short>(const std::string_view s);
|
||||||
|
template std::optional<unsigned int> string2Int<unsigned int>(const std::string_view s);
|
||||||
|
template std::optional<unsigned long> string2Int<unsigned long>(const std::string_view s);
|
||||||
|
template std::optional<unsigned long long> string2Int<unsigned long long>(const std::string_view s);
|
||||||
|
template std::optional<signed char> string2Int<signed char>(const std::string_view s);
|
||||||
|
template std::optional<signed short> string2Int<signed short>(const std::string_view s);
|
||||||
|
template std::optional<signed int> string2Int<signed int>(const std::string_view s);
|
||||||
|
template std::optional<signed long> string2Int<signed long>(const std::string_view s);
|
||||||
|
template std::optional<signed long long> string2Int<signed long long>(const std::string_view s);
|
||||||
|
|
||||||
|
template<class N>
|
||||||
|
std::optional<N> string2Float(const std::string_view s)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
return boost::lexical_cast<N>(s.data(), s.size());
|
||||||
|
} catch (const boost::bad_lexical_cast &) {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template std::optional<double> string2Float<double>(const std::string_view s);
|
||||||
|
template std::optional<float> string2Float<float>(const std::string_view s);
|
||||||
|
|
||||||
|
|
||||||
std::string toLower(const std::string & s)
|
std::string toLower(const std::string & s)
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
#include "error.hh"
|
#include "error.hh"
|
||||||
#include "types.hh"
|
#include "types.hh"
|
||||||
|
|
||||||
#include <boost/lexical_cast.hpp>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
@ -130,16 +129,7 @@ inline std::string rewriteStrings(std::string s, const StringMap & rewrites)
|
||||||
* Parse a string into an integer.
|
* Parse a string into an integer.
|
||||||
*/
|
*/
|
||||||
template<class N>
|
template<class N>
|
||||||
std::optional<N> string2Int(const std::string_view s)
|
std::optional<N> string2Int(const std::string_view s);
|
||||||
{
|
|
||||||
if (s.substr(0, 1) == "-" && !std::numeric_limits<N>::is_signed)
|
|
||||||
return std::nullopt;
|
|
||||||
try {
|
|
||||||
return boost::lexical_cast<N>(s.data(), s.size());
|
|
||||||
} catch (const boost::bad_lexical_cast &) {
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Like string2Int(), but support an optional suffix 'K', 'M', 'G' or
|
* Like string2Int(), but support an optional suffix 'K', 'M', 'G' or
|
||||||
|
@ -169,14 +159,7 @@ N string2IntWithUnitPrefix(std::string_view s)
|
||||||
* Parse a string into a float.
|
* Parse a string into a float.
|
||||||
*/
|
*/
|
||||||
template<class N>
|
template<class N>
|
||||||
std::optional<N> string2Float(const std::string_view s)
|
std::optional<N> string2Float(const std::string_view s);
|
||||||
{
|
|
||||||
try {
|
|
||||||
return boost::lexical_cast<N>(s.data(), s.size());
|
|
||||||
} catch (const boost::bad_lexical_cast &) {
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -9,8 +9,9 @@
|
||||||
#include "eval-inline.hh"
|
#include "eval-inline.hh"
|
||||||
#include "profiles.hh"
|
#include "profiles.hh"
|
||||||
#include "print-ambiguous.hh"
|
#include "print-ambiguous.hh"
|
||||||
#include <limits>
|
|
||||||
|
|
||||||
|
#include <limits>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <sstream>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue