================ @@ -80,15 +78,56 @@ class OptTable { const char *AliasArgs; const char *Values; - StringRef getName() const { - unsigned PrefixLength = Prefixes.empty() ? 0 : Prefixes[0].size(); - return PrefixedName.drop_front(PrefixLength); + bool hasNoPrefix() const { return PrefixesOffset == 0; } + + unsigned getNumPrefixes(ArrayRef<unsigned> PrefixesTable) const { + return PrefixesTable[PrefixesOffset]; + } + + ArrayRef<unsigned> + getPrefixOffsets(ArrayRef<unsigned> PrefixesTable) const { + return hasNoPrefix() ? ArrayRef<unsigned>() + : PrefixesTable.slice(PrefixesOffset + 1, + getNumPrefixes(PrefixesTable)); + } + + void appendPrefixes(const char *StrTable, ArrayRef<unsigned> PrefixesTable, + SmallVectorImpl<StringRef> &Prefixes) const { + for (unsigned PrefixOffset : getPrefixOffsets(PrefixesTable)) + Prefixes.push_back(&StrTable[PrefixOffset]); + } + + StringRef getPrefix(const char *StrTable, ArrayRef<unsigned> PrefixesTable, + unsigned PrefixIndex) const { + return &StrTable[getPrefixOffsets(PrefixesTable)[PrefixIndex]]; + } + + StringRef getPrefixedName(const char *StrTable) const { + return &StrTable[PrefixedNameOffset]; + } + + StringRef getName(const char *StrTable, + ArrayRef<unsigned> PrefixesTable) const { + unsigned PrefixLength = + hasNoPrefix() ? 0 : getPrefix(StrTable, PrefixesTable, 0).size(); + return getPrefixedName(StrTable).drop_front(PrefixLength); } }; private: + // A unified string table for these options. Individual strings are stored as + // null terminated C-strings at offsets within this table. + const char *StrTable; ---------------- chandlerc wrote:
Happy to use a `StringRef` if folks want here. I'm not sure about the exact construction though -- I think it'll be annoyingly important that we use something that gets the accelerated implementations of `strlen` when extracting strings from the table. And not sure that `StringRef` has a good tool for doing that in a way that *also* tracks a bound. But what's your preference about me cutting `StringRef` into the code as-is, versus waiting and coming back through to add a dedicated string table abstraction? Because that would let us have much nicer APIs compared to lifting this into `StringRef`. And it'll have to touch almost exactly the same lines I think. https://github.com/llvm/llvm-project/pull/119198 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits