Commit 72fb37ea authored by Sergei Golubchik's avatar Sergei Golubchik

cleanup: uuid

parent bdaa7fac
...@@ -1022,15 +1022,28 @@ int my_getpagesize(void); ...@@ -1022,15 +1022,28 @@ int my_getpagesize(void);
int my_msync(int, void *, size_t, int); int my_msync(int, void *, size_t, int);
#define MY_UUID_SIZE 16 #define MY_UUID_SIZE 16
#define MY_UUID_STRING_LENGTH (8+1+4+1+4+1+4+1+12) #define MY_UUID_BARE_STRING_LENGTH (8+4+4+4+12)
#define MY_UUID_ORACLE_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_init(ulong seed1, ulong seed2);
void my_uuid(uchar *guid); 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); 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); const char *my_dlerror(const char *dlpath);
/* character sets */ /* character sets */
......
...@@ -216,37 +216,6 @@ void my_uuid(uchar *to) ...@@ -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() void my_uuid_end()
{ {
if (my_uuid_inited) if (my_uuid_inited)
......
...@@ -535,7 +535,7 @@ static char *add_id_to_buffer(char *ptr, const LEX_CUSTRING *from) ...@@ -535,7 +535,7 @@ static char *add_id_to_buffer(char *ptr, const LEX_CUSTRING *from)
tmp.str= buff; tmp.str= buff;
tmp.length= MY_UUID_STRING_LENGTH; tmp.length= MY_UUID_STRING_LENGTH;
my_uuid2str(from->str, buff); my_uuid2str(from->str, buff, 1);
return add_str_to_buffer(ptr, &tmp); return add_str_to_buffer(ptr, &tmp);
} }
......
...@@ -4518,18 +4518,14 @@ String *Item_func_uuid::val_str(String *str) ...@@ -4518,18 +4518,14 @@ String *Item_func_uuid::val_str(String *str)
{ {
DBUG_ASSERT(fixed()); DBUG_ASSERT(fixed());
uchar guid[MY_UUID_SIZE]; uchar guid[MY_UUID_SIZE];
size_t length= (without_separators ? size_t length= without_separators ? MY_UUID_BARE_STRING_LENGTH
MY_UUID_ORACLE_STRING_LENGTH : : MY_UUID_STRING_LENGTH;
MY_UUID_STRING_LENGTH);
str->alloc(length+1); str->alloc(length+1);
str->length(length); str->length(length);
str->set_charset(system_charset_info); str->set_charset(system_charset_info);
my_uuid(guid); my_uuid(guid);
if (without_separators) my_uuid2str(guid, (char *)str->ptr(), !without_separators);
my_uuid2str_oracle(guid, (char *)str->ptr());
else
my_uuid2str(guid, (char *)str->ptr());
return str; return str;
} }
......
...@@ -2043,8 +2043,8 @@ Item_func_uuid(THD *thd, bool without_separators_arg): Item_str_func(thd), ...@@ -2043,8 +2043,8 @@ Item_func_uuid(THD *thd, bool without_separators_arg): Item_str_func(thd),
bool fix_length_and_dec() override bool fix_length_and_dec() override
{ {
collation.set(DTCollation_numeric()); collation.set(DTCollation_numeric());
fix_char_length(without_separators ? MY_UUID_ORACLE_STRING_LENGTH : fix_char_length(without_separators ? MY_UUID_BARE_STRING_LENGTH
MY_UUID_STRING_LENGTH); : MY_UUID_STRING_LENGTH);
return FALSE; return FALSE;
} }
bool const_item() const override { return false; } bool const_item() const override { return false; }
......
...@@ -1592,7 +1592,7 @@ static void descript(HA_CHECK *param, register MARIA_HA *info, char *name) ...@@ -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)); compile_time_assert((MY_UUID_STRING_LENGTH + 1) <= sizeof(buff));
buff[MY_UUID_STRING_LENGTH]= 0; buff[MY_UUID_STRING_LENGTH]= 0;
my_uuid2str(share->base.uuid, buff); my_uuid2str(share->base.uuid, buff, 1);
printf("UUID: %s\n", buff); printf("UUID: %s\n", buff);
if (ma_control_file_inited() && if (ma_control_file_inited() &&
memcmp(share->base.uuid, maria_uuid, MY_UUID_SIZE)) memcmp(share->base.uuid, maria_uuid, MY_UUID_SIZE))
......
...@@ -705,7 +705,7 @@ my_bool print_aria_log_control() ...@@ -705,7 +705,7 @@ my_bool print_aria_log_control()
checkpoint_lsn= lsn_korr(buffer + new_cf_create_time_size + checkpoint_lsn= lsn_korr(buffer + new_cf_create_time_size +
CF_LSN_OFFSET); CF_LSN_OFFSET);
logno= uint4korr(buffer + new_cf_create_time_size + CF_FILENO_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; uuid_str[MY_UUID_STRING_LENGTH]= 0;
printf("Block size: %u\n", uint2korr(buffer + CF_BLOCKSIZE_OFFSET)); printf("Block size: %u\n", uint2korr(buffer + CF_BLOCKSIZE_OFFSET));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment