diff options
| author | David Stone <davidfromonline@gmail.com> | 2025-11-21 15:43:27 -0700 |
|---|---|---|
| committer | David Stone <davidfromonline@gmail.com> | 2025-11-21 16:13:51 -0700 |
| commit | 3a3f129553947bcbe84558c9865bf554e033caea (patch) | |
| tree | 7038e0210afa92446829ca46f7a79fa337d71efc | |
| parent | e724009f2f449dfcfb44c29f39872b56f6a85af1 (diff) | |
[llvm] Replace `OwningArrayRef` with `std::vector` in `BTFParser`users/davidstone/replace-owning-array-ref-in-btf-parser
`OwningArrayRef` requires that the size and the capacity are the same. This prevents reusing memory allocations unless the size happens to be exactly the same (which is rare enough we don't even try). Switch to `std::vector` instead so that we're not repeatedly calling `new[]` and `delete[]`.
| -rw-r--r-- | llvm/include/llvm/DebugInfo/BTF/BTFParser.h | 2 | ||||
| -rw-r--r-- | llvm/lib/DebugInfo/BTF/BTFParser.cpp | 5 |
2 files changed, 4 insertions, 3 deletions
diff --git a/llvm/include/llvm/DebugInfo/BTF/BTFParser.h b/llvm/include/llvm/DebugInfo/BTF/BTFParser.h index f8b5b29738b3..32644e6700e7 100644 --- a/llvm/include/llvm/DebugInfo/BTF/BTFParser.h +++ b/llvm/include/llvm/DebugInfo/BTF/BTFParser.h @@ -46,7 +46,7 @@ class BTFParser { // A copy of types table from the object file but using native byte // order. Should not be too big in practice, e.g. for ~250MiB vmlinux // image it is ~4MiB. - OwningArrayRef<uint8_t> TypesBuffer; + std::vector<uint8_t> TypesBuffer; // Maps ELF section number to instruction line number information. // Each BTFLinesVector is sorted by `InsnOffset` to allow fast lookups. diff --git a/llvm/lib/DebugInfo/BTF/BTFParser.cpp b/llvm/lib/DebugInfo/BTF/BTFParser.cpp index 4fc31a445603..971a0d9f0176 100644 --- a/llvm/lib/DebugInfo/BTF/BTFParser.cpp +++ b/llvm/lib/DebugInfo/BTF/BTFParser.cpp @@ -206,7 +206,8 @@ Error BTFParser::parseTypesInfo(ParseContext &Ctx, uint64_t TypesInfoStart, StringRef RawData) { using support::endian::byte_swap; - TypesBuffer = OwningArrayRef<uint8_t>(arrayRefFromStringRef(RawData)); + auto RawDataAsBytes = arrayRefFromStringRef(RawData); + TypesBuffer.assign(RawDataAsBytes.begin(), RawDataAsBytes.end()); // Switch endianness if necessary. endianness Endianness = Ctx.Obj.isLittleEndian() ? llvm::endianness::little : llvm::endianness::big; @@ -380,7 +381,7 @@ Error BTFParser::parse(const ObjectFile &Obj, const ParseOptions &Opts) { SectionLines.clear(); SectionRelocs.clear(); Types.clear(); - TypesBuffer = OwningArrayRef<uint8_t>(); + TypesBuffer.clear(); ParseContext Ctx(Obj, Opts); std::optional<SectionRef> BTF; |
