[tz] [PATCH] Change is_digit from macro to function
Paul Eggert
eggert at cs.ucla.edu
Sat Sep 11 17:36:55 UTC 2021
This is cleaner and should be no slower with modern optimizers.
* localtime.c, zdump.c (is_digit):
New static function, replacing the old macro.
* private.h (is_digit): Remove this macro.
---
localtime.c | 7 +++++++
private.h | 3 ---
zdump.c | 8 ++++++--
3 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/localtime.c b/localtime.c
index 5f362d4..cc972ef 100644
--- a/localtime.c
+++ b/localtime.c
@@ -778,6 +778,13 @@ static const int year_lengths[2] = {
DAYSPERNYEAR, DAYSPERLYEAR
};
+/* Is C an ASCII digit? */
+static bool
+is_digit(char c)
+{
+ return '0' <= c && c <= '9';
+}
+
/*
** Given a pointer into a timezone string, scan until a character that is not
** a valid character in a time zone abbreviation is found.
diff --git a/private.h b/private.h
index 98ead55..4c03324 100644
--- a/private.h
+++ b/private.h
@@ -225,9 +225,6 @@
#define R_OK 4
#endif /* !defined R_OK */
-/* Unlike <ctype.h>'s isdigit, this also works if c < 0 | c > UCHAR_MAX. */
-#define is_digit(c) ((unsigned)(c) - '0' <= 9)
-
/*
** Define HAVE_STDINT_H's default value here, rather than at the
** start, since __GLIBC__ and INTMAX_MAX's values depend on
diff --git a/zdump.c b/zdump.c
index 3c71894..9d22b26 100644
--- a/zdump.c
+++ b/zdump.c
@@ -99,8 +99,12 @@ static void showtrans(char const *, struct tm const *, time_t, char const *,
static const char *tformat(void);
static time_t yeartot(intmax_t) ATTRIBUTE_PURE;
-/* Unlike <ctype.h>'s isdigit, this also works if c < 0 | c > UCHAR_MAX. */
-#define is_digit(c) ((unsigned)(c) - '0' <= 9)
+/* Is C an ASCII digit? */
+static bool
+is_digit(char c)
+{
+ return '0' <= c && c <= '9';
+}
/* Is A an alphabetic character in the C locale? */
static bool
--
2.31.1
More information about the tz
mailing list