[libc++] Avoid including <cmath> in <format> (#186332)

This reduces the time to parse `<format>` a bit.
This commit is contained in:
Nikolas Klauser
2026-03-16 11:27:21 +01:00
committed by GitHub
parent 5b9e2924d2
commit c2e739f3bb
3 changed files with 8 additions and 10 deletions

View File

@@ -32,12 +32,12 @@
#include <__format/formatter_output.h>
#include <__format/parser_std_format_spec.h>
#include <__iterator/concepts.h>
#include <__math/traits.h>
#include <__memory/allocator.h>
#include <__system_error/errc.h>
#include <__type_traits/conditional.h>
#include <__utility/move.h>
#include <__utility/unreachable.h>
#include <cmath>
#if _LIBCPP_HAS_LOCALIZATION
# include <__locale>
@@ -637,10 +637,10 @@ _LIBCPP_HIDE_FROM_ABI auto __write_using_trailing_zeros(
template <floating_point _Tp, class _CharT, class _FormatContext>
_LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator
__format_floating_point(_Tp __value, _FormatContext& __ctx, __format_spec::__parsed_specifications<_CharT> __specs) {
bool __negative = std::signbit(__value);
bool __negative = __math::signbit(__value);
if (!std::isfinite(__value)) [[unlikely]]
return __formatter::__format_floating_point_non_finite(__ctx.out(), __specs, __negative, std::isnan(__value));
if (!__math::isfinite(__value)) [[unlikely]]
return __formatter::__format_floating_point_non_finite(__ctx.out(), __specs, __negative, __math::isnan(__value));
// Depending on the std-format-spec string the sign and the value
// might not be outputted together:

View File

@@ -233,12 +233,15 @@ namespace std {
# pragma GCC system_header
# endif
# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 23
# include <cmath>
# endif
# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
# include <array>
# include <cctype>
# include <cerrno>
# include <clocale>
# include <cmath>
# include <cstddef>
# include <cstdint>
# include <cstdlib>

View File

@@ -354,7 +354,6 @@ format cctype
format cerrno
format climits
format clocale
format cmath
format compare
format cstddef
format cstdint
@@ -508,7 +507,6 @@ iostream cctype
iostream cerrno
iostream climits
iostream clocale
iostream cmath
iostream compare
iostream cstddef
iostream cstdint
@@ -694,7 +692,6 @@ ostream cctype
ostream cerrno
ostream climits
ostream clocale
ostream cmath
ostream compare
ostream cstddef
ostream cstdint
@@ -724,7 +721,6 @@ print cctype
print cerrno
print climits
print clocale
print cmath
print compare
print cstddef
print cstdint
@@ -995,7 +991,6 @@ syncstream cctype
syncstream cerrno
syncstream climits
syncstream clocale
syncstream cmath
syncstream compare
syncstream cstddef
syncstream cstdint
1 algorithm cctype
354 format cerrno
355 format climits
356 format clocale
format cmath
357 format compare
358 format cstddef
359 format cstdint
507 iostream cerrno
508 iostream climits
509 iostream clocale
iostream cmath
510 iostream compare
511 iostream cstddef
512 iostream cstdint
692 ostream cerrno
693 ostream climits
694 ostream clocale
ostream cmath
695 ostream compare
696 ostream cstddef
697 ostream cstdint
721 print cerrno
722 print climits
723 print clocale
print cmath
724 print compare
725 print cstddef
726 print cstdint
991 syncstream cerrno
992 syncstream climits
993 syncstream clocale
syncstream cmath
994 syncstream compare
995 syncstream cstddef
996 syncstream cstdint