Skip to content

Commit 72fb37e

Browse files
committed
cleanup: uuid
1 parent bdaa7fa commit 72fb37e

File tree

7 files changed

+25
-47
lines changed

7 files changed

+25
-47
lines changed

include/my_sys.h

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,15 +1022,28 @@ int my_getpagesize(void);
10221022
int my_msync(int, void *, size_t, int);
10231023

10241024
#define MY_UUID_SIZE 16
1025-
#define MY_UUID_STRING_LENGTH (8+1+4+1+4+1+4+1+12)
1026-
#define MY_UUID_ORACLE_STRING_LENGTH (8+4+4+4+12)
1025+
#define MY_UUID_BARE_STRING_LENGTH (8+4+4+4+12)
1026+
#define MY_UUID_SEPARATORS 4
1027+
#define MY_UUID_STRING_LENGTH (MY_UUID_BARE_STRING_LENGTH + MY_UUID_SEPARATORS)
10271028

10281029
void my_uuid_init(ulong seed1, ulong seed2);
10291030
void my_uuid(uchar *guid);
1030-
void my_uuid2str(const uchar *guid, char *s);
1031-
void my_uuid2str_oracle(const uchar *guid, char *s);
10321031
void my_uuid_end(void);
10331032

1033+
static inline void my_uuid2str(const uchar *guid, char *s, int with_separators)
1034+
{
1035+
int i;
1036+
int mask= with_separators ? ((1 << 3) | (1 << 5) | (1 << 7) | (1 << 9)) : 0;
1037+
for (i=0; i < MY_UUID_SIZE; i++, mask >>= 1)
1038+
{
1039+
*s++= _dig_vec_lower[guid[i] >>4];
1040+
*s++= _dig_vec_lower[guid[i] & 15];
1041+
if (mask & 1)
1042+
*s++= '-';
1043+
}
1044+
}
1045+
1046+
10341047
const char *my_dlerror(const char *dlpath);
10351048

10361049
/* character sets */

mysys/my_uuid.c

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -216,37 +216,6 @@ void my_uuid(uchar *to)
216216
}
217217

218218

219-
/**
220-
Convert uuid to string representation
221-
222-
@func my_uuid2str()
223-
@param guid uuid
224-
@param s Output buffer.Must be at least MY_UUID_STRING_LENGTH+1 large.
225-
*/
226-
void my_uuid2str(const uchar *guid, char *s)
227-
{
228-
int i;
229-
for (i=0; i < MY_UUID_SIZE; i++)
230-
{
231-
*s++= _dig_vec_lower[guid[i] >>4];
232-
*s++= _dig_vec_lower[guid[i] & 15];
233-
/* Set '-' at intervals 3, 5, 7 and 9 */
234-
if ((1 << i) & ((1 << 3) | (1 << 5) | (1 << 7) | (1 << 9)))
235-
*s++= '-';
236-
}
237-
}
238-
239-
void my_uuid2str_oracle(const uchar *guid, char *s)
240-
{
241-
int i;
242-
for (i=0; i < MY_UUID_SIZE; i++)
243-
{
244-
*s++= _dig_vec_upper[guid[i] >>4];
245-
*s++= _dig_vec_upper[guid[i] & 15];
246-
}
247-
}
248-
249-
250219
void my_uuid_end()
251220
{
252221
if (my_uuid_inited)

sql/backup.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ static char *add_id_to_buffer(char *ptr, const LEX_CUSTRING *from)
535535

536536
tmp.str= buff;
537537
tmp.length= MY_UUID_STRING_LENGTH;
538-
my_uuid2str(from->str, buff);
538+
my_uuid2str(from->str, buff, 1);
539539
return add_str_to_buffer(ptr, &tmp);
540540
}
541541

sql/item_strfunc.cc

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4518,18 +4518,14 @@ String *Item_func_uuid::val_str(String *str)
45184518
{
45194519
DBUG_ASSERT(fixed());
45204520
uchar guid[MY_UUID_SIZE];
4521-
size_t length= (without_separators ?
4522-
MY_UUID_ORACLE_STRING_LENGTH :
4523-
MY_UUID_STRING_LENGTH);
4521+
size_t length= without_separators ? MY_UUID_BARE_STRING_LENGTH
4522+
: MY_UUID_STRING_LENGTH;
45244523

45254524
str->alloc(length+1);
45264525
str->length(length);
45274526
str->set_charset(system_charset_info);
45284527
my_uuid(guid);
4529-
if (without_separators)
4530-
my_uuid2str_oracle(guid, (char *)str->ptr());
4531-
else
4532-
my_uuid2str(guid, (char *)str->ptr());
4528+
my_uuid2str(guid, (char *)str->ptr(), !without_separators);
45334529
return str;
45344530
}
45354531

sql/item_strfunc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2043,8 +2043,8 @@ Item_func_uuid(THD *thd, bool without_separators_arg): Item_str_func(thd),
20432043
bool fix_length_and_dec() override
20442044
{
20452045
collation.set(DTCollation_numeric());
2046-
fix_char_length(without_separators ? MY_UUID_ORACLE_STRING_LENGTH :
2047-
MY_UUID_STRING_LENGTH);
2046+
fix_char_length(without_separators ? MY_UUID_BARE_STRING_LENGTH
2047+
: MY_UUID_STRING_LENGTH);
20482048
return FALSE;
20492049
}
20502050
bool const_item() const override { return false; }

storage/maria/aria_chk.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1592,7 +1592,7 @@ static void descript(HA_CHECK *param, register MARIA_HA *info, char *name)
15921592
}
15931593
compile_time_assert((MY_UUID_STRING_LENGTH + 1) <= sizeof(buff));
15941594
buff[MY_UUID_STRING_LENGTH]= 0;
1595-
my_uuid2str(share->base.uuid, buff);
1595+
my_uuid2str(share->base.uuid, buff, 1);
15961596
printf("UUID: %s\n", buff);
15971597
if (ma_control_file_inited() &&
15981598
memcmp(share->base.uuid, maria_uuid, MY_UUID_SIZE))

storage/maria/ma_control_file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ my_bool print_aria_log_control()
705705
checkpoint_lsn= lsn_korr(buffer + new_cf_create_time_size +
706706
CF_LSN_OFFSET);
707707
logno= uint4korr(buffer + new_cf_create_time_size + CF_FILENO_OFFSET);
708-
my_uuid2str(buffer + CF_UUID_OFFSET, uuid_str);
708+
my_uuid2str(buffer + CF_UUID_OFFSET, uuid_str, 1);
709709
uuid_str[MY_UUID_STRING_LENGTH]= 0;
710710

711711
printf("Block size: %u\n", uint2korr(buffer + CF_BLOCKSIZE_OFFSET));

0 commit comments

Comments
 (0)