Skip to content

Commit 9688b98

Browse files
committed
fix: make Uuid inherit util::Formattable and add unlikely
1 parent 79f00bc commit 9688b98

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/iceberg/util/uuid.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
#include "iceberg/exception.h"
2929
#include "iceberg/result.h"
30+
#include "iceberg/util/formatter.h" // IWYU pragma: keep
3031
#include "iceberg/util/int128.h"
3132
#include "iceberg/util/macros.h"
3233

@@ -70,7 +71,7 @@ inline Result<Uuid> ParseSimple(std::string_view s) {
7071
uint8_t h1 = kHexTable[static_cast<uint8_t>(s[i * 2])];
7172
uint8_t h2 = kHexTable[static_cast<uint8_t>(s[i * 2 + 1])];
7273

73-
if ((h1 | h2) == 0xFF) {
74+
if ((h1 | h2) == 0xFF) [[unlikely]] {
7475
return InvalidArgument("Invalid UUID string: {}", s);
7576
}
7677

@@ -84,7 +85,7 @@ inline Result<Uuid> ParseHyphenated(std::string_view s) {
8485
ICEBERG_DCHECK(s.size() == 36, "s must be 36 characters long");
8586

8687
// Check that dashes are in the right places
87-
if (!(s[8] == '-' && s[13] == '-' && s[18] == '-' && s[23] == '-')) {
88+
if (!(s[8] == '-' && s[13] == '-' && s[18] == '-' && s[23] == '-')) [[unlikely]] {
8889
return InvalidArgument("Invalid UUID string: {}", s);
8990
}
9091

@@ -98,7 +99,7 @@ inline Result<Uuid> ParseHyphenated(std::string_view s) {
9899
uint8_t h3 = kHexTable[static_cast<uint8_t>(s[i + 2])];
99100
uint8_t h4 = kHexTable[static_cast<uint8_t>(s[i + 3])];
100101

101-
if ((h1 | h2 | h3 | h4) == 0xFF) {
102+
if ((h1 | h2 | h3 | h4) == 0xFF) [[unlikely]] {
102103
return InvalidArgument("Invalid UUID string: {}", s);
103104
}
104105

src/iceberg/util/uuid.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@
2626

2727
#include "iceberg/iceberg_export.h"
2828
#include "iceberg/result.h"
29+
#include "iceberg/util/formattable.h"
2930

3031
/// \file iceberg/util/uuid.h
3132
/// \brief UUID (Universally Unique Identifier) representation.
3233

3334
namespace iceberg {
3435

35-
class ICEBERG_EXPORT Uuid {
36+
class ICEBERG_EXPORT Uuid : public util::Formattable {
3637
public:
3738
Uuid() = delete;
3839
constexpr static size_t kLength = 16;
@@ -71,7 +72,7 @@ class ICEBERG_EXPORT Uuid {
7172
uint8_t operator[](size_t index) const;
7273

7374
/// \brief Convert the UUID to a string in standard format.
74-
std::string ToString() const;
75+
std::string ToString() const override;
7576

7677
friend bool operator==(const Uuid& lhs, const Uuid& rhs) {
7778
return lhs.data_ == rhs.data_;

0 commit comments

Comments
 (0)