From 72fb37ea89f2ababc1a145208b5efbd9b140a183 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Tue, 17 Aug 2021 16:58:17 +0200 Subject: [PATCH] cleanup: uuid --- include/my_sys.h | 21 +++++++++++++++++---- mysys/my_uuid.c | 31 ------------------------------- sql/backup.cc | 2 +- sql/item_strfunc.cc | 10 +++------- sql/item_strfunc.h | 4 ++-- storage/maria/aria_chk.c | 2 +- storage/maria/ma_control_file.c | 2 +- 7 files changed, 25 insertions(+), 47 deletions(-) diff --git a/include/my_sys.h b/include/my_sys.h index b3c23e8e6fa..f63fe38aab8 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -1022,15 +1022,28 @@ int my_getpagesize(void); int my_msync(int, void *, size_t, int); #define MY_UUID_SIZE 16 -#define MY_UUID_STRING_LENGTH (8+1+4+1+4+1+4+1+12) -#define MY_UUID_ORACLE_STRING_LENGTH (8+4+4+4+12) +#define MY_UUID_BARE_STRING_LENGTH (8+4+4+4+12) +#define MY_UUID_SEPARATORS 4 +#define MY_UUID_STRING_LENGTH (MY_UUID_BARE_STRING_LENGTH + MY_UUID_SEPARATORS) void my_uuid_init(ulong seed1, ulong seed2); void my_uuid(uchar *guid); -void my_uuid2str(const uchar *guid, char *s); -void my_uuid2str_oracle(const uchar *guid, char *s); void my_uuid_end(void); +static inline void my_uuid2str(const uchar *guid, char *s, int with_separators) +{ + int i; + int mask= with_separators ? ((1 << 3) | (1 << 5) | (1 << 7) | (1 << 9)) : 0; + for (i=0; i < MY_UUID_SIZE; i++, mask >>= 1) + { + *s++= _dig_vec_lower[guid[i] >>4]; + *s++= _dig_vec_lower[guid[i] & 15]; + if (mask & 1) + *s++= '-'; + } +} + + const char *my_dlerror(const char *dlpath); /* character sets */ diff --git a/mysys/my_uuid.c b/mysys/my_uuid.c index 72c8fa8507d..7925f80191b 100644 --- a/mysys/my_uuid.c +++ b/mysys/my_uuid.c @@ -216,37 +216,6 @@ void my_uuid(uchar *to) } -/** - Convert uuid to string representation - - @func my_uuid2str() - @param guid uuid - @param s Output buffer.Must be at least MY_UUID_STRING_LENGTH+1 large. -*/ -void my_uuid2str(const uchar *guid, char *s) -{ - int i; - for (i=0; i < MY_UUID_SIZE; i++) - { - *s++= _dig_vec_lower[guid[i] >>4]; - *s++= _dig_vec_lower[guid[i] & 15]; - /* Set '-' at intervals 3, 5, 7 and 9 */ - if ((1 << i) & ((1 << 3) | (1 << 5) | (1 << 7) | (1 << 9))) - *s++= '-'; - } -} - -void my_uuid2str_oracle(const uchar *guid, char *s) -{ - int i; - for (i=0; i < MY_UUID_SIZE; i++) - { - *s++= _dig_vec_upper[guid[i] >>4]; - *s++= _dig_vec_upper[guid[i] & 15]; - } -} - - void my_uuid_end() { if (my_uuid_inited) diff --git a/sql/backup.cc b/sql/backup.cc index 208e1694b3a..89cc9b6ee15 100644 --- a/sql/backup.cc +++ b/sql/backup.cc @@ -535,7 +535,7 @@ static char *add_id_to_buffer(char *ptr, const LEX_CUSTRING *from) tmp.str= buff; tmp.length= MY_UUID_STRING_LENGTH; - my_uuid2str(from->str, buff); + my_uuid2str(from->str, buff, 1); return add_str_to_buffer(ptr, &tmp); } diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 0567501c97a..e6f7597fa91 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -4518,18 +4518,14 @@ String *Item_func_uuid::val_str(String *str) { DBUG_ASSERT(fixed()); uchar guid[MY_UUID_SIZE]; - size_t length= (without_separators ? - MY_UUID_ORACLE_STRING_LENGTH : - MY_UUID_STRING_LENGTH); + size_t length= without_separators ? MY_UUID_BARE_STRING_LENGTH + : MY_UUID_STRING_LENGTH; str->alloc(length+1); str->length(length); str->set_charset(system_charset_info); my_uuid(guid); - if (without_separators) - my_uuid2str_oracle(guid, (char *)str->ptr()); - else - my_uuid2str(guid, (char *)str->ptr()); + my_uuid2str(guid, (char *)str->ptr(), !without_separators); return str; } diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h index 1f925053241..7884addf5f5 100644 --- a/sql/item_strfunc.h +++ b/sql/item_strfunc.h @@ -2043,8 +2043,8 @@ Item_func_uuid(THD *thd, bool without_separators_arg): Item_str_func(thd), bool fix_length_and_dec() override { collation.set(DTCollation_numeric()); - fix_char_length(without_separators ? MY_UUID_ORACLE_STRING_LENGTH : - MY_UUID_STRING_LENGTH); + fix_char_length(without_separators ? MY_UUID_BARE_STRING_LENGTH + : MY_UUID_STRING_LENGTH); return FALSE; } bool const_item() const override { return false; } diff --git a/storage/maria/aria_chk.c b/storage/maria/aria_chk.c index 266b11d99f5..7d5598f06b5 100644 --- a/storage/maria/aria_chk.c +++ b/storage/maria/aria_chk.c @@ -1592,7 +1592,7 @@ static void descript(HA_CHECK *param, register MARIA_HA *info, char *name) } compile_time_assert((MY_UUID_STRING_LENGTH + 1) <= sizeof(buff)); buff[MY_UUID_STRING_LENGTH]= 0; - my_uuid2str(share->base.uuid, buff); + my_uuid2str(share->base.uuid, buff, 1); printf("UUID: %s\n", buff); if (ma_control_file_inited() && memcmp(share->base.uuid, maria_uuid, MY_UUID_SIZE)) diff --git a/storage/maria/ma_control_file.c b/storage/maria/ma_control_file.c index d71f92c2eac..db74ba0af75 100644 --- a/storage/maria/ma_control_file.c +++ b/storage/maria/ma_control_file.c @@ -705,7 +705,7 @@ my_bool print_aria_log_control() checkpoint_lsn= lsn_korr(buffer + new_cf_create_time_size + CF_LSN_OFFSET); logno= uint4korr(buffer + new_cf_create_time_size + CF_FILENO_OFFSET); - my_uuid2str(buffer + CF_UUID_OFFSET, uuid_str); + my_uuid2str(buffer + CF_UUID_OFFSET, uuid_str, 1); uuid_str[MY_UUID_STRING_LENGTH]= 0; printf("Block size: %u\n", uint2korr(buffer + CF_BLOCKSIZE_OFFSET));