[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    [PATCH 1/5] pw_encrypt.c: make i64c() slightly smaller
From:       Rasmus Villemoes <rasmus.villemoes () prevas ! dk>
Date:       2024-04-15 12:56:24
Message-ID: 20240415125628.780178-2-rasmus.villemoes () prevas ! dk
[Download RAW message or body]

In ASCII at least, '.' is 0x2e, '/' is 0x2f and '0' is 0x30. So the
existing "if (i < 12)" case does the right thing also for i <= 1.

I don't know if busybox supports anything but ASCII environments, but
since we can do it build-time with preprocessor conditionals, we might
as well leave the two cases in the code, which then (along with the
terse comment) also serves as a bit of explanation for what the i<12
case then ends up producing.

function                                             old     new   delta
i64c                                                  41      24     -17
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-17)             Total: -17 bytes

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
---
 libbb/pw_encrypt.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libbb/pw_encrypt.c b/libbb/pw_encrypt.c
index 3463fd95b..adbdc1d1e 100644
--- a/libbb/pw_encrypt.c
+++ b/libbb/pw_encrypt.c
@@ -20,10 +20,13 @@
 static int i64c(int i)
 {
 	i &= 0x3f;
+	/* In ascii, '.', '/' and '0' are consecutive. */
+#if '0' - 2 != '.' || '0' - 1 != '/'
 	if (i == 0)
 		return '.';
 	if (i == 1)
 		return '/';
+#endif
 	if (i < 12)
 		return ('0' - 2 + i);
 	if (i < 38)
-- 
2.40.1.1.g1c60b9335d

_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic