Optimize circular buffer to avoid modulo
authorRose <83477269+AtariDreams@users.noreply.github.com>
Tue, 19 Dec 2023 16:19:38 +0000 (11:19 -0500)
committerTomas Mraz <tomas@openssl.org>
Fri, 22 Dec 2023 13:45:55 +0000 (14:45 +0100)
CLA: trivial

Avoid doing the division via modulo where possible.

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/23097)

crypto/bio/bio_dump.c

index c453da62688c6cf7efab531df38436d8194c7c7b..40c18410e4cf073f7f65530a8967eb5600e655ce 100644 (file)
@@ -141,9 +141,10 @@ int BIO_hex_string(BIO *out, int indent, int width, const void *data,
 
         BIO_printf(out, "%02X:", d[i]);
 
-        j = (j + 1) % width;
-        if (!j)
+        if (++j >= width) {
+            j = 0;
             BIO_printf(out, "\n");
+        }
     }
 
     if (i && !j)