diff options
author | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2024-03-15 00:33:19 +0100 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2024-03-18 01:48:46 +0100 |
commit | e6c7a88b34c5db0811a57dda54f8a4f13246b858 (patch) | |
tree | 62d2a6cf30b9060965653903f2b5a7fcd2288f90 /libavutil | |
parent | 95a6788314a2f5080e8d5488dd5ba1040abeba6f (diff) | |
download | ffmpeg-e6c7a88b34c5db0811a57dda54f8a4f13246b858.tar.gz |
avutil/hash: Avoid relocations for hash names
These strings are so short (longest takes 11B) that using
pointers is wasteful. Avoiding them also moves hashdesc
into .rodata (from .data.rel.ro).
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavutil')
-rw-r--r-- | libavutil/hash.c | 72 |
1 files changed, 41 insertions, 31 deletions
diff --git a/libavutil/hash.c b/libavutil/hash.c index 12333982fb..fbc24194de 100644 --- a/libavutil/hash.c +++ b/libavutil/hash.c @@ -18,6 +18,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include <assert.h> #include <stddef.h> #include <stdint.h> #include <stdio.h> @@ -38,22 +39,27 @@ #include "intreadwrite.h" #include "mem.h" +// ENTRY(HASH_TYPE, HASH_NAME, HASH_SIZE) +#define HASHES(ENTRY) \ + ENTRY(MD5, "MD5", 16) \ + ENTRY(MURMUR3, "murmur3", 16) \ + ENTRY(RIPEMD128, "RIPEMD128", 16) \ + ENTRY(RIPEMD160, "RIPEMD160", 20) \ + ENTRY(RIPEMD256, "RIPEMD256", 32) \ + ENTRY(RIPEMD320, "RIPEMD320", 40) \ + ENTRY(SHA160, "SHA160", 20) \ + ENTRY(SHA224, "SHA224", 28) \ + ENTRY(SHA256, "SHA256", 32) \ + ENTRY(SHA512_224, "SHA512/224", 28) \ + ENTRY(SHA512_256, "SHA512/256", 32) \ + ENTRY(SHA384, "SHA384", 48) \ + ENTRY(SHA512, "SHA512", 64) \ + ENTRY(CRC32, "CRC32", 4) \ + ENTRY(ADLER32, "adler32", 4) \ + enum hashtype { - MD5, - MURMUR3, - RIPEMD128, - RIPEMD160, - RIPEMD256, - RIPEMD320, - SHA160, - SHA224, - SHA256, - SHA512_224, - SHA512_256, - SHA384, - SHA512, - CRC32, - ADLER32, +#define HASH_TYPE(TYPE, NAME, SIZE) TYPE, + HASHES(HASH_TYPE) NUM_HASHES }; @@ -64,25 +70,29 @@ typedef struct AVHashContext { uint32_t crc; } AVHashContext; +#define HASH_MAX_SIZE(TYPE, NAME, SIZE) \ + HASH_MAX_SIZE_BEFORE_ ## TYPE, \ + HASH_MAX_SIZE_UNTIL_ ## TYPE ## _MINUS_ONE = FFMAX(SIZE, HASH_MAX_SIZE_BEFORE_ ## TYPE) - 1, +enum { + HASHES(HASH_MAX_SIZE) + MAX_HASH_SIZE +}; +static_assert(AV_HASH_MAX_SIZE >= MAX_HASH_SIZE, "AV_HASH_MAX_SIZE needs to be updated!"); + +#define HASH_MAX_NAME_SIZE(TYPE, NAME, SIZE) \ + HASH_MAX_NAME_SIZE_BEFORE_ ## TYPE, \ + HASH_MAX_NAME_SIZE_UNTIL_ ## TYPE ## _MINUS_ONE = FFMAX(sizeof(NAME), HASH_MAX_NAME_SIZE_BEFORE_ ## TYPE) - 1, +enum { + HASHES(HASH_MAX_NAME_SIZE) + MAX_HASH_NAME_SIZE +}; + static const struct { - const char *name; + const char name[MAX_HASH_NAME_SIZE]; int size; } hashdesc[] = { - [MD5] = {"MD5", 16}, - [MURMUR3] = {"murmur3", 16}, - [RIPEMD128] = {"RIPEMD128", 16}, - [RIPEMD160] = {"RIPEMD160", 20}, - [RIPEMD256] = {"RIPEMD256", 32}, - [RIPEMD320] = {"RIPEMD320", 40}, - [SHA160] = {"SHA160", 20}, - [SHA224] = {"SHA224", 28}, - [SHA256] = {"SHA256", 32}, - [SHA512_224] = {"SHA512/224", 28}, - [SHA512_256] = {"SHA512/256", 32}, - [SHA384] = {"SHA384", 48}, - [SHA512] = {"SHA512", 64}, - [CRC32] = {"CRC32", 4}, - [ADLER32] = {"adler32", 4}, +#define HASH_DESC(TYPE, NAME, SIZE) [TYPE] = { NAME, SIZE }, + HASHES(HASH_DESC) }; const char *av_hash_names(int i) |