[llvm] [DebugNames] Compare TableEntry names more efficiently (PR #79759)

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 29 15:37:56 PST 2024


dwblaikie wrote:

> Why not use strncmp? We can't use the "N" argument of strncmp to be std::min(<debug_str_starting_at_name>.size(), Target.size()), as this would return "equal" when Target is a prefix of Name. To work around this, we would need to require Target to be null-terminated.

Rather than requiring `Target` to be null terminated, an extra check after strncmp could be done, yeah? (checking that `<debug_str_starting_at_name>[Target.size()] == `\0`)

So the function could be written, I think, as `return Data.size() >= Target.size() && strncmp(Data.data(), Target.data(), Target.size()) == 0 && !Data[Target.size()];` I think? Something like that

> The final argument for not using strcmp/strncmp is that they did provide any measurable speed benefits when compared to the proposed patch.

Could you elaborate on this further - did strncmp provide equivalent benefits to this proposed patch? But was avoided because of the extra requirement (null termination of `Target`, currently satisfied, but not necessarily true in the future?) 

https://github.com/llvm/llvm-project/pull/79759


More information about the llvm-commits mailing list