Skip to content

Conversation

@davidstone
Copy link
Contributor

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[].

`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[]`.
@llvmbot
Copy link
Member

llvmbot commented Nov 21, 2025

@llvm/pr-subscribers-debuginfo

Author: David Stone (davidstone)

Changes

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[].


Full diff: https://github.com/llvm/llvm-project/pull/169124.diff

2 Files Affected:

  • (modified) llvm/include/llvm/DebugInfo/BTF/BTFParser.h (+1-1)
  • (modified) llvm/lib/DebugInfo/BTF/BTFParser.cpp (+3-2)
diff --git a/llvm/include/llvm/DebugInfo/BTF/BTFParser.h b/llvm/include/llvm/DebugInfo/BTF/BTFParser.h
index f8b5b29738b3f..32644e6700e78 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 4fc31a4456031..971a0d9f01769 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;

@github-actions
Copy link

🐧 Linux x64 Test Results

  • 186457 tests passed
  • 4866 tests skipped

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants