Commit f215c5f0 authored by Kenton Varda's avatar Kenton Varda

Don't include kj/units.h at all in capnp/common.h if not compiling with debug types.

Since this header is included by everyone, and units.h has lots of templates, this seems like it could significantly improve build times.
parent 168cb630
......@@ -34,6 +34,7 @@
#include <kj/mutex.h>
#include <kj/exception.h>
#include <kj/vector.h>
#include <kj/units.h>
#include "common.h"
#include "message.h"
#include "layout.h"
......
......@@ -30,11 +30,14 @@
#pragma GCC system_header
#endif
#include <kj/units.h>
#include <inttypes.h>
#include <kj/string.h>
#include <kj/memory.h>
#if CAPNP_DEBUG_TYPES
#include <kj/units.h>
#endif
namespace capnp {
#define CAPNP_VERSION_MAJOR 0
......
......@@ -592,6 +592,21 @@ static KJ_CONSTEXPR(const) MinValue_ minValue = MinValue_();
//
// `char` is not supported, but `signed char` and `unsigned char` are.
template <uint bits>
inline constexpr unsigned long long maxValueForBits() {
// Get the maximum integer representable in the given number of bits.
// 1ull << 64 is unfortunately undefined.
return (bits == 64 ? 0 : (1ull << bits)) - 1;
}
struct ThrowOverflow {
// Functor which throws an exception complaining about integer overflow. Usually this is used
// with the interfaces in units.h, but is defined here because Cap'n Proto wants to avoid
// including units.h when not using CAPNP_DEBUG_TYPES.
void operator()() const;
};
#if __GNUC__
inline constexpr float inf() { return __builtin_huge_valf(); }
inline constexpr float nan() { return __builtin_nanf(""); }
......
......@@ -497,14 +497,6 @@ template <uint bits>
using AtLeastUInt = typename AtLeastUInt_<bitCount<max(bits, 1) - 1>()>::Type;
// AtLeastUInt<n> is an unsigned integer of at least n bits. E.g. AtLeastUInt<12> is uint16_t.
template <uint bits>
inline constexpr uint64_t maxValueForBits() {
// Get the maximum integer representable in the given number of bits.
// 1ull << 64 is unfortunately undefined.
return (bits == 64 ? 0 : (1ull << bits)) - 1;
}
// -------------------------------------------------------------------
template <uint value>
......@@ -808,10 +800,6 @@ inline constexpr auto assumeMax(Quantity<BoundedConst<maxN>, Unit>, Quantity<Num
return assumeMax<maxN>(value);
}
struct ThrowOverflow {
void operator()() const;
};
template <uint64_t newMax, uint64_t maxN, typename T, typename ErrorFunc>
inline constexpr Bounded<newMax, T> assertMax(Bounded<maxN, T> value, ErrorFunc&& errorFunc) {
// Assert that the bounded value is less than or equal to the given maximum, calling errorFunc()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment