I don't think it was wrong before, but the strchr() in particular left
me scratching my head. This formulation is slightly cheaper and seems
more obviously correct.

(Unrelated but nearby, I don't understand why anyone would ever want to
calculate these tables at runtime, so this seems like another
unnecessary CFG_TOYBOX_FLOAT to me, though an unusual one where we might
want to _remove_ the floating-point code.)
---
 toys/lsb/md5sum.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
From 3541519845b15ee77afcdef777c745a9d69369f1 Mon Sep 17 00:00:00 2001
From: Elliott Hughes <e...@google.com>
Date: Tue, 8 Jun 2021 12:33:10 -0700
Subject: [PATCH] md5sum.c: simplify the table setup slightly.

I don't think it was wrong before, but the strchr() in particular left
me scratching my head. This formulation is slightly cheaper and seems
more obviously correct.

(Unrelated but nearby, I don't understand why anyone would ever want to
calculate these tables at runtime, so this seems like another
unnecessary CFG_TOYBOX_FLOAT to me, though an unusual one where we might
want to _remove_ the floating-point code.)
---
 toys/lsb/md5sum.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/toys/lsb/md5sum.c b/toys/lsb/md5sum.c
index 4df53a5c..feb403f7 100644
--- a/toys/lsb/md5sum.c
+++ b/toys/lsb/md5sum.c
@@ -514,10 +514,10 @@ void md5sum_main(void)
         TT.rconsttable32 = xmalloc(64*4);
         for (i = 0; i<64; i++) TT.rconsttable32[i] = fabs(sin(i+1))*(1LL<<32);
       } else TT.rconsttable32 = md5nofloat;
-    } else if (strchr("25", toys.which->name[4])) { // 224, 256
+    } else if (toys.which->name[3] == '2') { // sha224, sha256
       TT.rconsttable32 = xmalloc(64*4);
       for (i=0; i<64; i++) TT.rconsttable32[i] = sha512nofloat[i] >> 32;
-    } else if (toys.which->name[3] != '1') TT.rconsttable64 = sha512nofloat;
+    } else TT.rconsttable64 = sha512nofloat; // sha384, sha512
   }
 
   if (FLAG(c)) for (i = 0; toys.optargs[i]; i++) do_c_file(toys.optargs[i]);
-- 
2.32.0.rc1.229.g3e70b5a671-goog

_______________________________________________
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to