[PATCH 23/59] Minor tzfile.c clarity improvements

Paul Eggert eggert@cs.ucla.edu
Sun Jan 5 05:56:58 GMT 2025


* time/tzfile.c (__tzfile_read, __tzfile_compute):
Avoid some unnecesary unsigned char -> int conversions.
Improve clarity of loop controlling.
---
 time/tzfile.c | 23 +++++++++--------------
 1 file changed, 9 insertions(+), 14 deletions(-)

diff --git a/time/tzfile.c b/time/tzfile.c
index 8d8391acfe..291b3aa0dd 100644
--- a/time/tzfile.c
+++ b/time/tzfile.c
@@ -508,16 +508,14 @@ __tzfile_read (const char *file)
      transitioned to earliest in time.  */
   __tzname[0] = NULL;
   __tzname[1] = NULL;
-  for (i = timecnt; i > 0; )
+  for (i = timecnt; i > 0; i--)
     {
-      int type = type_idxs[--i];
-      int dst = types[type].dst;
+      struct ttinfo *ttype = &types[type_idxs[i - 1]];
+      unsigned char dst = ttype->dst;
 
       if (__tzname[dst] == NULL)
 	{
-	  int idx = types[type].idx;
-
-	  __tzname[dst] = __tzstring (&zone_names[idx]);
+	  __tzname[dst] = __tzstring (&zone_names[ttype->idx]);
 
 	  if (__tzname[1 - dst] != NULL)
 	    break;
@@ -699,22 +697,19 @@ __tzfile_compute (__time64_t timer, int use_localtime,
 	     && (i == timecnt || timer < transitions[i])); */
 	  __tzname[types[type_idxs[i - 1]].dst]
 	    = __tzstring (&zone_names[types[type_idxs[i - 1]].idx]);
-	  tzidx j = i;
-	  while (j < timecnt)
+
+	  for (tzidx j = i; j < timecnt; j++)
 	    {
-	      int type = type_idxs[j];
-	      int dst = types[type].dst;
-	      int idx = types[type].idx;
+	      struct ttinfo *ttype = &types[type_idxs[j]];
+	      unsigned char dst = ttype->dst;
 
 	      if (__tzname[dst] == NULL)
 		{
-		  __tzname[dst] = __tzstring (&zone_names[idx]);
+		  __tzname[dst] = __tzstring (&zone_names[ttype->idx]);
 
 		  if (__tzname[1 - dst] != NULL)
 		    break;
 		}
-
-	      ++j;
 	    }
 
 	  if (__glibc_unlikely (__tzname[0] == NULL))
-- 
2.45.2



More information about the Libc-alpha mailing list