Pádraig Brady <p...@draigbrady.com> writes: > It turns out I can greatly improve the performance further! > > Before: > $ time yes | head -c65535 | src/basenc --base58 -w0 >file.enc > real 0m1.533s > > After: > $ time yes | head -c65535 | src/basenc --base58 -w0 >file.enc > real 0m0.018s > > I was reading the GMP source out of interest (go open source), > and noticed that it supported base conversion internally, > which we could just call and then map the alternate character set after.
Nice work! > -static char const base58_alphabet[58] _GL_ATTRIBUTE_NONSTRING = > - "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; This hunk was removed in this patch, but I noticed that basenc.c is the only .c file to use _GL_ATTRIBUTE_... instead of the ones from attributes.h which look nicer and are less likely to change. I pushed the attatched patch to change them and added a syntax-check. > + *outlen = p - out; > > return; > } Harmless, but this return can be removed. Collin
>From 13202995bafc11fc7c881bcdae4c6f10da78c83b Mon Sep 17 00:00:00 2001 Message-ID: <13202995bafc11fc7c881bcdae4c6f10da78c83b.1754711640.git.collin.fu...@gmail.com> From: Collin Funk <collin.fu...@gmail.com> Date: Fri, 8 Aug 2025 20:32:18 -0700 Subject: [PATCH] maint: prefer attribute.h in .c files * src/basenc.c (base16_encode, z85_encoding, do_decode): Use ATTRIBUTE_NONSTRING instead of ATTRIBUTE_NONSTRING. * src/basenc.c (sc_prohibit-_gl-attributes): New rule for 'make syntax-check'. --- cfg.mk | 7 +++++++ src/basenc.c | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/cfg.mk b/cfg.mk index 2115b8441..4c634f663 100644 --- a/cfg.mk +++ b/cfg.mk @@ -304,6 +304,13 @@ sc_prohibit-gl-attributes: halt='Use _GL... attribute macros' \ $(_sc_search_regexp) +# Ensure that <attributes.h> macros are used in .c files. +sc_prohibit-_gl-attributes: + @prohibit='_GL_ATTRIBUTE' \ + in_vc_files='\.c$$' \ + halt='Use ATTRIBUTE_... instead of _GL_ATTRIBUTE_...' \ + $(_sc_search_regexp) + # Prefer the const declaration form, with const following the type sc_prohibit-const-char: @prohibit='const char \*' \ diff --git a/src/basenc.c b/src/basenc.c index 3f550a71f..c445e6f41 100644 --- a/src/basenc.c +++ b/src/basenc.c @@ -626,7 +626,7 @@ static void base16_encode (char const *restrict in, idx_t inlen, char *restrict out, idx_t outlen) { - static const char base16[16] _GL_ATTRIBUTE_NONSTRING = "0123456789ABCDEF"; + static const char base16[16] ATTRIBUTE_NONSTRING = "0123456789ABCDEF"; while (inlen && outlen) { @@ -711,7 +711,7 @@ isuz85 (unsigned char ch) return c_isalnum (ch) || strchr (".-:+=^!/*?&<>()[]{}@%$#", ch) != nullptr; } -static char const z85_encoding[85] _GL_ATTRIBUTE_NONSTRING = +static char const z85_encoding[85] ATTRIBUTE_NONSTRING = "0123456789" "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" @@ -1136,7 +1136,7 @@ do_decode (FILE *in, char const *infile, FILE *out, bool ignore_garbage) idx_t sum; struct base_decode_context ctx; - char padbuf[8] _GL_ATTRIBUTE_NONSTRING = "========"; + char padbuf[8] ATTRIBUTE_NONSTRING = "========"; inbuf = xmalloc (BASE_LENGTH (DEC_BLOCKSIZE)); outbuf = xmalloc (DEC_BLOCKSIZE); -- 2.50.1