This change also prevents looking further than the size of the current
UUID.
Details
Diff Detail
- Build Status
Buildable 12535 Build 12535: arc lint + arc unit
Event Timeline
You could use llvm's range adapters to make this slightly better.
auto Bytes = makeArrayRef(m_uuid, m_num_uuid_bytes); return llvm::find(Bytes, 0) != Bytes.end();
Another option would just be return *this != UUID(m_num_uuid_bytes);
Yes, what Zachary said. Thanks for the cleanup. There's a decent amount of code in lldb that can be written in a very compact way but it's manually unrolled. I think in this case the code produced should be equivalent (and if not, I'd be curious to see the codegen).
More generally, whenever a function is not in a hot loop, we might consider preferring readability over performances anyway.
A better solution would be to initialize UUID::m_num_uuid_bytes with zero and only set it to a valid value if we set bytes into it. Then UUID::IsValid() becomes easy:
bool UUID::IsValid() const { return m_num_uuid_bytes > 0; }
This would allows us to actually have a UUID value that is valid and all zeroes. A few comments would need to be fixed as it currently assumes length is 16 or 20.
We want at least one non-zero element, we don't want a zero-element, so the proposed code wouldn't work. I'm not sure if there's an llvm utility that allows doing that directly without having to pass a lambda.
Yes but the current default constructor of the UUID class creates a 16-bytes all-zeroes UUID. I'm not sure I want to be changing the default behavior that the rest of lldb might be depending on currently.
Wouldn't the other alternative work, where you just use operator== against a default constructed instance?
The other alternative seems a bit less explicit to me but I don't mind it too much. What's the issue with using std::any_of exactly?
No one is relying on the 16 bytes of zeroes that I know of. UUID::IsValid() is the test that everyone uses to tell if the UUID is valid or not. I still prefer to just set the length to zero as this does allow us to have a UUID of all zeroes if needed.