From: Jo Sutton Date: Wed, 1 Mar 2023 01:54:14 +0000 (+1300) Subject: librpc: Speed up GUID_buf_string() X-Git-Tag: tdb-1.4.13~1279 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=09655e13eab4ab2fe4c36bf899e5fe5e2c3622a0;p=thirdparty%2Fsamba.git librpc: Speed up GUID_buf_string() This is faster than calling snprintf(). Signed-off-by: Jo Sutton Reviewed-by: Douglas Bagnall --- diff --git a/librpc/ndr/uuid.c b/librpc/ndr/uuid.c index 9fcf12bda90..ce094cc9a50 100644 --- a/librpc/ndr/uuid.c +++ b/librpc/ndr/uuid.c @@ -205,15 +205,58 @@ _PUBLIC_ char* GUID_buf_string(const struct GUID *guid, if (!guid) { return NULL; } - snprintf(dst->buf, sizeof(dst->buf), - "%08"PRIx32"-%04"PRIx16"-%04"PRIx16"-%02"PRIx8"%02"PRIx8"-%02"PRIx8"%02"PRIx8"%02"PRIx8"%02"PRIx8"%02"PRIx8"%02"PRIx8, - guid->time_low, guid->time_mid, - guid->time_hi_and_version, - guid->clock_seq[0], - guid->clock_seq[1], - guid->node[0], guid->node[1], - guid->node[2], guid->node[3], - guid->node[4], guid->node[5]); + + if (sizeof(dst->buf) < 37) { + return NULL; + } + + dst->buf[0] = nybble_to_hex_lower(guid->time_low >> 28); + dst->buf[1] = nybble_to_hex_lower(guid->time_low >> 24); + dst->buf[2] = nybble_to_hex_lower(guid->time_low >> 20); + dst->buf[3] = nybble_to_hex_lower(guid->time_low >> 16); + dst->buf[4] = nybble_to_hex_lower(guid->time_low >> 12); + dst->buf[5] = nybble_to_hex_lower(guid->time_low >> 8); + dst->buf[6] = nybble_to_hex_lower(guid->time_low >> 4); + dst->buf[7] = nybble_to_hex_lower(guid->time_low); + + dst->buf[8] = '-'; + + dst->buf[9] = nybble_to_hex_lower(guid->time_mid >> 12); + dst->buf[10] = nybble_to_hex_lower(guid->time_mid >> 8); + dst->buf[11] = nybble_to_hex_lower(guid->time_mid >> 4); + dst->buf[12] = nybble_to_hex_lower(guid->time_mid); + + dst->buf[13] = '-'; + + dst->buf[14] = nybble_to_hex_lower(guid->time_hi_and_version >> 12); + dst->buf[15] = nybble_to_hex_lower(guid->time_hi_and_version >> 8); + dst->buf[16] = nybble_to_hex_lower(guid->time_hi_and_version >> 4); + dst->buf[17] = nybble_to_hex_lower(guid->time_hi_and_version); + + dst->buf[18] = '-'; + + dst->buf[19] = nybble_to_hex_lower(guid->clock_seq[0] >> 4); + dst->buf[20] = nybble_to_hex_lower(guid->clock_seq[0]); + dst->buf[21] = nybble_to_hex_lower(guid->clock_seq[1] >> 4); + dst->buf[22] = nybble_to_hex_lower(guid->clock_seq[1]); + + dst->buf[23] = '-'; + + dst->buf[24] = nybble_to_hex_lower(guid->node[0] >> 4); + dst->buf[25] = nybble_to_hex_lower(guid->node[0]); + dst->buf[26] = nybble_to_hex_lower(guid->node[1] >> 4); + dst->buf[27] = nybble_to_hex_lower(guid->node[1]); + dst->buf[28] = nybble_to_hex_lower(guid->node[2] >> 4); + dst->buf[29] = nybble_to_hex_lower(guid->node[2]); + dst->buf[30] = nybble_to_hex_lower(guid->node[3] >> 4); + dst->buf[31] = nybble_to_hex_lower(guid->node[3]); + dst->buf[32] = nybble_to_hex_lower(guid->node[4] >> 4); + dst->buf[33] = nybble_to_hex_lower(guid->node[4]); + dst->buf[34] = nybble_to_hex_lower(guid->node[5] >> 4); + dst->buf[35] = nybble_to_hex_lower(guid->node[5]); + + dst->buf[36] = '\0'; + return dst->buf; }