@@ -47,42 +47,39 @@ static inline const char* tr_as_array(T item)
47
47
48
48
static inline char * to_string (const UUID& uuid)
49
49
{
50
- const uint8_t * Buffer = uuid. getBaseUUID () ;
51
- const uint8_t Length = uuid. getLen () ;
52
- const size_t Row_Count = 4 ;
50
+ static constexpr const size_t ROW_COUNT = 4 ;
51
+ static constexpr const char *HEX = " 0123456789ABCDEF " ;
52
+ static constexpr const size_t HYPHENS_DELIMITER_COUNT = 4 ;
53
53
54
- const char *Hex = " 0123456789ABCDEF" ;
55
-
56
- static char string_buffer[Row_Count][UUID::LENGTH_OF_LONG_UUID + /* Number of hyphen delimiters =*/ 4 ];
54
+ static char string_buffer[ROW_COUNT][UUID::LENGTH_OF_LONG_UUID + HYPHENS_DELIMITER_COUNT];
57
55
static uint8_t idx = 0 ;
58
56
59
57
++idx;
60
58
61
- if (idx == Row_Count ) {
59
+ if (idx == ROW_COUNT ) {
62
60
idx= 0 ;
63
61
}
64
62
65
- char * p1 = (char *)Buffer + Length - 1 ;
66
- char * p2 = string_buffer[idx];
63
+ const uint8_t length = uuid.getLen ();
64
+ const char * reader = (const char *) uuid.getBaseUUID () + length - 1 ;
65
+ char * writer = string_buffer[idx];
67
66
68
- if (Length == UUID::LENGTH_OF_LONG_UUID) {
69
- const uint8_t format[] = {4 , 2 , 2 , 2 , 6 };
70
- for ( uint8_t i: format) {
71
- size_t j = 0 ;
72
- for (; j < i; ++j) {
73
- *p2++ = Hex[(*p1 >> 4 ) & 0xF ];
74
- *p2++ = Hex[(*p1--) & 0xF ];
67
+ if (length == UUID::LENGTH_OF_LONG_UUID) {
68
+ constexpr uint8_t format[] = {4 , 2 , 2 , 2 , 6 };
69
+ for ( uint8_t char_count: format) {
70
+ for (size_t i = 0 ; i < char_count; ++i) {
71
+ *writer++ = HEX[(*reader >> 4 ) & 0xF ];
72
+ *writer++ = HEX[(*reader--) & 0xF ];
75
73
}
76
- *p2 ++ = ' -' ;
74
+ *writer ++ = ' -' ;
77
75
}
78
- *--p2 = 0 ;
76
+ *--writer = 0 ;
79
77
} else {
80
- size_t i = 0 ;
81
- for (; i < Length; ++i) {
82
- *p2++ = Hex[(*p1 >> 4 ) & 0xF ];
83
- *p2++ = Hex[(*p1--) & 0xF ];
78
+ for (size_t i = 0 ; i < length; ++i) {
79
+ *writer++ = HEX[(*reader >> 4 ) & 0xF ];
80
+ *writer++ = HEX[(*reader--) & 0xF ];
84
81
}
85
- *p2 = 0 ;
82
+ *writer = 0 ;
86
83
}
87
84
88
85
return string_buffer[idx];
0 commit comments