]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
librpc: Speed up GUID_buf_string()
authorJo Sutton <josutton@catalyst.net.nz>
Wed, 1 Mar 2023 01:54:14 +0000 (14:54 +1300)
committerDouglas Bagnall <dbagnall@samba.org>
Wed, 28 Aug 2024 04:24:39 +0000 (04:24 +0000)
This is faster than calling snprintf().

Signed-off-by: Jo Sutton <josutton@catalyst.net.nz>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
librpc/ndr/uuid.c

index 9fcf12bda90889c8b10157810babcefbded60c16..ce094cc9a50df706de5b9085ac8ffc9f72572b44 100644 (file)
@@ -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;
 }