util: Add dedicated hex conversion functions and use it.

This deduplicate two identical bytes_to_hex implementation into one.

The intention is to ease the introduction of a new hash algorithm, which
will also have its formatting helper (to ensure seamless transition from
sha1).

Note that the new functions always take the size of the binary buffer,
unlike the old disk_cache_format_hex_id which took `binary * 2` which was
inconsistent (binary size is `binary` and string size is `binary * 2 + 1`).

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22527>
This commit is contained in:
Tatsuyuki Ishi
2023-04-17 22:08:24 +09:00
committed by Marge Bot
parent 96a0b1e988
commit 681d8cd9ea
4 changed files with 75 additions and 25 deletions
+2 -10
View File
@@ -33,6 +33,7 @@
#include <stdint.h>
#include <stdbool.h>
#include <sys/stat.h>
#include "util/hex.h"
#include "util/mesa-sha1.h"
#include "util/detect_os.h"
@@ -82,16 +83,7 @@ struct disk_cache;
static inline char *
disk_cache_format_hex_id(char *buf, const uint8_t *hex_id, unsigned size)
{
static const char hex_digits[] = "0123456789abcdef";
unsigned i;
for (i = 0; i < size; i += 2) {
buf[i] = hex_digits[hex_id[i >> 1] >> 4];
buf[i + 1] = hex_digits[hex_id[i >> 1] & 0x0f];
}
buf[i] = '\0';
return buf;
return mesa_bytes_to_hex(buf, hex_id, size / 2);
}
#ifdef HAVE_DLADDR