[committed] libstdc++: Add lightweight replacement for std::numeric_limits (PR 92546)

Jonathan Wakely jwakely@redhat.com
Fri Feb 28 21:56:00 GMT 2020


On 17/02/20 15:32 +0000, Jonathan Wakely wrote:
>Many uses of std::numeric_limits in C++17 and C++20 features only really
>need the min(), max() and digits constants for integral types. By adding
>__detail::__int_limits we can avoid including the whole <limits> header.
>
>The <limits> header isn't especially large, but avoiding it still gives
>small savings in compilation time and memory usage for the compiler.
>
>There are also C++11 features that could benefit from this change (e.g.
><bits/hashtable_policy.h> and <bits/uniform_int_dist.h>) but I won't
>change those until stage 1.
>
>The implementation of __int_limits assumes two's complement integers,
>which is true for all targets supported by GCC.
>
>	PR libstdc++/92546 (partial)
>	* include/Makefile.am: Add new header.
>	* include/Makefile.in: Regenerate.
>	* include/bits/int_limits.h: New header.
>	* include/bits/parse_numbers.h (__select_int::_Select_int): Replace
>	numeric_limits with __detail::__int_limits.
>	* include/std/bit (__rotl, __rotr, __countl_zero, __countl_one)
>	(__countr_zero, __countr_one, __popcount, __ceil2, __floor2, __log2p1):
>	Likewise.
>	* include/std/charconv (__to_chars_8, __from_chars_binary)
>	(__from_chars_alpha_to_num, from_chars): Likewise.
>	* include/std/memory_resource (polymorphic_allocator::allocate)
>	(polymorphic_allocator::allocate_object): Likewise.
>	* include/std/string_view (basic_string_view::_S_compare): Likewise.
>	* include/std/utility (in_range): Likewise.
>	* testsuite/20_util/integer_comparisons/in_range_neg.cc: Adjust for
>	extra error about incomplete type __int_limits<bool>.
>	* testsuite/26_numerics/bit/bit.count/countl_one.cc: Include <limits>.
>	* testsuite/26_numerics/bit/bit.count/countl_zero.cc: Likewise.
>	* testsuite/26_numerics/bit/bit.count/countr_one.cc: Likewise.
>	* testsuite/26_numerics/bit/bit.count/countr_zero.cc: Likewise.
>	* testsuite/26_numerics/bit/bit.count/popcount.cc: Likewise.
>	* testsuite/26_numerics/bit/bit.pow.two/ceil2_neg.cc: Likewise.
>	* testsuite/26_numerics/bit/bit.pow.two/ceil2.cc: Likewise.
>	* testsuite/26_numerics/bit/bit.pow.two/floor2.cc: Likewise.
>	* testsuite/26_numerics/bit/bit.pow.two/ispow2.cc: Likewise.
>	* testsuite/26_numerics/bit/bit.pow.two/log2p1.cc: Likewise.
>	* testsuite/26_numerics/bit/bit.rotate/rotl.cc: Likewise.
>	* testsuite/26_numerics/bit/bit.rotate/rotr.cc: Likewise.
>
>Tested powerpc64le-linux, committed to master.

I think I probably should have just used __gnu_cxx::__numeric_traits
instead of adding a new trait. That already has min, max and digits
and is much smaller than the whole of <limits>.



More information about the Libstdc++ mailing list