summaryrefslogtreecommitdiffstats
path: root/lldb/source/Utility/UUID.cpp
diff options
context:
space:
mode:
authorPavel Labath <labath@google.com>2018-06-21 15:07:43 +0000
committerPavel Labath <labath@google.com>2018-06-21 15:07:43 +0000
commit470b286ee5669019a83b2e2ffae845ee44369fbf (patch)
tree6bb572eb8d9527ee580308d25363a284a0330efa /lldb/source/Utility/UUID.cpp
parent084d360f6984df29d0ea2bdf8fea1f1d97de2858 (diff)
downloadbcm5719-llvm-470b286ee5669019a83b2e2ffae845ee44369fbf.tar.gz
bcm5719-llvm-470b286ee5669019a83b2e2ffae845ee44369fbf.zip
Modernize UUID class
Instead of a separate GetBytes + GetByteSize methods I introduce a single GetBytes method returning an ArrayRef. This is NFC cleanup now, but it should make handling arbitrarily-sized UUIDs cleaner, should we choose to go that way. I also took the opportunity to add some unit tests for this class. llvm-svn: 335244
Diffstat (limited to 'lldb/source/Utility/UUID.cpp')
-rw-r--r--lldb/source/Utility/UUID.cpp16
1 files changed, 7 insertions, 9 deletions
diff --git a/lldb/source/Utility/UUID.cpp b/lldb/source/Utility/UUID.cpp
index 097243219fa..864fb38eba1 100644
--- a/lldb/source/Utility/UUID.cpp
+++ b/lldb/source/Utility/UUID.cpp
@@ -46,14 +46,12 @@ void UUID::Clear() {
::memset(m_uuid, 0, sizeof(m_uuid));
}
-const void *UUID::GetBytes() const { return m_uuid; }
-
std::string UUID::GetAsString(const char *separator) const {
std::string result;
char buf[256];
if (!separator)
separator = "-";
- const uint8_t *u = (const uint8_t *)GetBytes();
+ const uint8_t *u = GetBytes().data();
if (sizeof(buf) >
(size_t)snprintf(buf, sizeof(buf), "%2.2X%2.2X%2.2X%2.2X%s%2.2X%2.2X%s%2."
"2X%2.2X%s%2.2X%2.2X%s%2.2X%2.2X%2.2X%"
@@ -101,8 +99,6 @@ bool UUID::SetBytes(const void *uuid_bytes, uint32_t num_uuid_bytes) {
return false;
}
-size_t UUID::GetByteSize() const { return m_num_uuid_bytes; }
-
bool UUID::IsValid() const {
return m_uuid[0] || m_uuid[1] || m_uuid[2] || m_uuid[3] || m_uuid[4] ||
m_uuid[5] || m_uuid[6] || m_uuid[7] || m_uuid[8] || m_uuid[9] ||
@@ -184,8 +180,7 @@ size_t UUID::SetFromCString(const char *cstr, uint32_t num_uuid_bytes) {
bool lldb_private::operator==(const lldb_private::UUID &lhs,
const lldb_private::UUID &rhs) {
- return ::memcmp(lhs.GetBytes(), rhs.GetBytes(),
- sizeof(lldb_private::UUID::ValueType)) == 0;
+ return lhs.GetBytes() == rhs.GetBytes();
}
bool lldb_private::operator!=(const lldb_private::UUID &lhs,
@@ -195,8 +190,11 @@ bool lldb_private::operator!=(const lldb_private::UUID &lhs,
bool lldb_private::operator<(const lldb_private::UUID &lhs,
const lldb_private::UUID &rhs) {
- return ::memcmp(lhs.GetBytes(), rhs.GetBytes(),
- sizeof(lldb_private::UUID::ValueType)) < 0;
+ if (lhs.GetBytes().size() != rhs.GetBytes().size())
+ return lhs.GetBytes().size() < rhs.GetBytes().size();
+
+ return std::memcmp(lhs.GetBytes().data(), rhs.GetBytes().data(),
+ lhs.GetBytes().size());
}
bool lldb_private::operator<=(const lldb_private::UUID &lhs,
OpenPOWER on IntegriCloud