mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-26 07:46:21 +02:00
Merge pull request #10812 from Mic92/build-perf
Remove 100s of CPU time (10%) from build times (1465s -> 1302s)
This commit is contained in:
commit
84e116379c
17 changed files with 59 additions and 31 deletions
|
@ -28,13 +28,13 @@
|
||||||
#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>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
#include <boost/container/small_vector.hpp>
|
#include <boost/container/small_vector.hpp>
|
||||||
|
|
|
@ -20,8 +20,6 @@
|
||||||
#pragma clang diagnostic ignored "-Wunneeded-internal-declaration"
|
#pragma clang diagnostic ignored "-Wunneeded-internal-declaration"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <boost/lexical_cast.hpp>
|
|
||||||
|
|
||||||
#include "nixexpr.hh"
|
#include "nixexpr.hh"
|
||||||
#include "parser-tab.hh"
|
#include "parser-tab.hh"
|
||||||
|
|
||||||
|
@ -129,9 +127,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 "print.hh"
|
#include "print.hh"
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <sstream>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
#include "print.hh"
|
#include "print.hh"
|
||||||
#include "ansicolor.hh"
|
#include "ansicolor.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>
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include <future>
|
#include <future>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
# include "monitor-fd.hh"
|
# include "monitor-fd.hh"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
namespace nix::daemon {
|
namespace nix::daemon {
|
||||||
|
|
||||||
Sink & operator << (Sink & sink, const Logger::Fields & fields)
|
Sink & operator << (Sink & sink, const Logger::Fields & fields)
|
||||||
|
|
|
@ -148,7 +148,7 @@ static Machine parseBuilderLine(const std::set<std::string> & defaultSystems, co
|
||||||
};
|
};
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include "file-system.hh"
|
#include "file-system.hh"
|
||||||
#include "processes.hh"
|
#include "processes.hh"
|
||||||
#include "signals.hh"
|
#include "signals.hh"
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
# include <mach-o/dyld.h>
|
# include <mach-o/dyld.h>
|
||||||
|
|
|
@ -20,8 +20,6 @@
|
||||||
#endif
|
#endif
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
#include <boost/lexical_cast.hpp>
|
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include "position.hh"
|
#include "position.hh"
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
#include <sstream>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
|
|
@ -12,8 +12,6 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
#include <boost/lexical_cast.hpp>
|
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
|
||||||
#include <sodium.h>
|
#include <sodium.h>
|
||||||
|
#include <boost/lexical_cast.hpp>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#ifdef NDEBUG
|
#ifdef NDEBUG
|
||||||
#error "Nix may not be built with assertions disabled (i.e. with -DNDEBUG)."
|
#error "Nix may not be built with assertions disabled (i.e. with -DNDEBUG)."
|
||||||
|
@ -111,6 +113,43 @@ std::string rewriteStrings(std::string s, const StringMap & rewrites)
|
||||||
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);
|
||||||
|
|
||||||
|
|
||||||
bool hasPrefix(std::string_view s, std::string_view prefix)
|
bool hasPrefix(std::string_view s, std::string_view prefix)
|
||||||
{
|
{
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
#include "error.hh"
|
#include "error.hh"
|
||||||
#include "logging.hh"
|
#include "logging.hh"
|
||||||
|
|
||||||
#include <boost/lexical_cast.hpp>
|
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
@ -102,16 +101,7 @@ 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
|
||||||
|
@ -141,14 +131,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 {
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,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