[16/59] Improve performance in 2 BC

Message ID 20250105055750.1668721-17-eggert@cs.ucla.edu (mailing list archive)
State New
Headers
Series time: sync mktime from Gnulib |

Checks

Context Check Description
redhat-pt-bot/TryBot-apply_patch success Patch applied to master at the time it was sent

Commit Message

Paul Eggert Jan. 5, 2025, 5:56 a.m. UTC
  * time/tzset.c: Include <limits.h>, for INT_MIN.
(parse_rule): Initialize computed_for to INT_MIN, not -1, as
INT_MIN is otherwise impossible after adding 1900.
(compute_change): Simplify accordingly.
---
 time/tzset.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
  

Patch

diff --git a/time/tzset.c b/time/tzset.c
index bd3509307e..e869fbf3fd 100644
--- a/time/tzset.c
+++ b/time/tzset.c
@@ -16,6 +16,7 @@ 
    <https://www.gnu.org/licenses/>.  */
 
 #include <ctype.h>
+#include <limits.h>
 #include <stdbool.h>
 #include <stdckdint.h>
 #include <stddef.h>
@@ -55,7 +56,8 @@  typedef struct
     /* We cache the computed time of change for a
        given year so we don't have to recompute it.  */
     __time64_t change;	/* When to change to this zone.  */
-    int computed_for;	/* Year above is computed for.  */
+    int computed_for;	/* Year that CHANGE is computed for.
+			   If INT_MIN, CHANGE is unspecified.  */
   } tz_rule;
 
 /* tz_rules[0] is standard, tz_rules[1] is daylight.  */
@@ -339,7 +341,7 @@  parse_rule (const char **tzp, int whichrule)
     secs = 2 * 60 * 60;
 
   tzr->secs = secs;
-  tzr->computed_for = -1;
+  tzr->computed_for = INT_MIN;
   *tzp = tz;
   return true;
 }
@@ -444,8 +446,7 @@  compute_change (tz_rule *rule, int year)
 {
   __time64_t t;
 
-  if (year != -1 && rule->computed_for == year)
-    /* Operations on times in 2 BC will be slower.  Oh well.  */
+  if (rule->computed_for == year)
     return;
 
   /* First set T to January 1st, 0:00:00 GMT in YEAR.  */