Skip to content

Commit bf7495e

Browse files
committed
fix: use std::format to simplify uuid ToString
1 parent 8056114 commit bf7495e

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

src/iceberg/util/uuid_util.cc

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -192,16 +192,12 @@ Result<std::array<uint8_t, 16>> UUIDUtils::FromString(std::string_view str) {
192192
std::string UUIDUtils::ToString(std::span<uint8_t> uuid) {
193193
static const char* hex_chars = "0123456789abcdef";
194194
ICEBERG_DCHECK(uuid.size() == 16, "uuid must be 16 bytes long");
195-
std::string str(36, '-');
196195

197-
for (size_t i = 0; i < 16; i++) {
198-
str[i * 2 + (i >= 4 ? 1 : 0) + (i >= 6 ? 1 : 0) + (i >= 8 ? 1 : 0) +
199-
(i >= 10 ? 1 : 0)] = hex_chars[(uuid[i] >> 4) & 0x0F];
200-
str[i * 2 + 1 + (i >= 4 ? 1 : 0) + (i >= 6 ? 1 : 0) + (i >= 8 ? 1 : 0) +
201-
(i >= 10 ? 1 : 0)] = hex_chars[uuid[i] & 0x0F];
202-
}
203-
204-
return str;
196+
return std::format(
197+
"{:02x}{:02x}{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}{:02x}"
198+
"{:02x}{:02x}{:02x}",
199+
uuid[0], uuid[1], uuid[2], uuid[3], uuid[4], uuid[5], uuid[6], uuid[7], uuid[8],
200+
uuid[9], uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], uuid[15]);
205201
}
206202

207203
} // namespace iceberg

0 commit comments

Comments
 (0)