Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce executable size overhead for embedded targets using newlib nano #839

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions include/fmt/format-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
#include <cmath>
#include <cstdarg>
#include <cstddef> // for std::ptrdiff_t
#if !defined(FMT_STATIC_THOUSANDS_SEPARATOR)
#include <locale>
#endif

#if defined(_WIN32) && defined(__MINGW32__)
# include <cstring>
Expand Down Expand Up @@ -193,6 +195,7 @@ void report_error(FormatFunc func, int error_code,
}
} // namespace

#if !defined(FMT_STATIC_THOUSANDS_SEPARATOR)
class locale {
private:
std::locale locale_;
Expand All @@ -202,6 +205,21 @@ class locale {
std::locale get() { return locale_; }
};

template <typename Char>
FMT_FUNC Char internal::thousands_sep(locale_provider *lp) {
std::locale loc = lp ? lp->locale().get() : std::locale();
return std::use_facet<std::numpunct<Char>>(loc).thousands_sep();
}

#else

template <typename Char>
FMT_FUNC Char internal::thousands_sep(locale_provider *lp) {
return FMT_STATIC_THOUSANDS_SEPARATOR;
}

#endif

FMT_FUNC size_t internal::count_code_points(u8string_view s) {
const char8_t *data = s.data();
int num_code_points = 0;
Expand All @@ -212,11 +230,6 @@ FMT_FUNC size_t internal::count_code_points(u8string_view s) {
return num_code_points;
}

template <typename Char>
FMT_FUNC Char internal::thousands_sep(locale_provider *lp) {
std::locale loc = lp ? lp->locale().get() : std::locale();
return std::use_facet<std::numpunct<Char>>(loc).thousands_sep();
}

FMT_FUNC void system_error::init(
int err_code, string_view format_str, format_args args) {
Expand Down Expand Up @@ -569,8 +582,9 @@ FMT_FUNC void vprint_rgb(rgb fd, rgb bg, string_view format, format_args args) {
std::fputs(internal::data::RESET_COLOR, stdout);
}
#endif

#if !defined(FMT_STATIC_THOUSANDS_SEPARATOR)
FMT_FUNC locale locale_provider::locale() { return fmt::locale(); }
#endif

FMT_END_NAMESPACE

Expand Down
2 changes: 1 addition & 1 deletion include/fmt/posix.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ class file {
long getpagesize();

#if (defined(LC_NUMERIC_MASK) || defined(_MSC_VER)) && \
!defined(__ANDROID__) && !defined(__CYGWIN__) && !defined(__OpenBSD__)
!defined(__ANDROID__) && !defined(__CYGWIN__) && !defined(__OpenBSD__) && !defined(__NEWLIB_H__)
# define FMT_LOCALE
#endif

Expand Down