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

Felipe de Azevedo Piovezan via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 30 12:06:22 PST 2024


felipepiovezan wrote:

I ended up amending the original commit to change its message, since the implementation is now vastly different.
For historical purposes, here is the original implementation:
```
    // Compares the name of this entry against Target, returning true if they
     // are equal. This is helpful is hot code paths that do not need the length
     // of the name.
     bool compareNameAgainst(StringRef Target) const {
       // Note: this is not the name, but the rest of debug_names starting from
       // name. This handles corrupt data (non-null terminated) without
       // overruning the buffer.
       auto Data = StrData.getData().substr(StringOffset);
       auto DataSize = Data.size();
       auto TargetSize = Target.size();

       // Invariant: at the start of the loop, we have non-null characters to
       // read from Data.
       size_t Idx = 0;
       for (; Idx < DataSize && Data[Idx]; Idx++) {
         if (Idx >= TargetSize || Data[Idx] != Target[Idx])
           return false;
       }
       return Idx == TargetSize;
     }
```

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


More information about the llvm-commits mailing list