[PATCH] D107652: [llvm-objcopy][ELF][NFC] Remove unneeded methods of Object

Igor Kudrin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 6 08:22:52 PDT 2021


ikudrin created this revision.
ikudrin added reviewers: jakehehrlich, jhenderson, MaskRay.
ikudrin added a project: LLVM.
Herald added subscribers: abrachet, emaste.
Herald added a reviewer: alexander-shaposhnikov.
Herald added a reviewer: rupprecht.
ikudrin requested review of this revision.

The patch removes mutable accessor methods for sections and segments. As for now, const variants of them are not used because all callers have mutable access to an instance of `Object`. On the other hand, they do not actually modify the sets, so it looks better to keep only const ones.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107652

Files:
  llvm/tools/llvm-objcopy/ELF/Object.h


Index: llvm/tools/llvm-objcopy/ELF/Object.h
===================================================================
--- llvm/tools/llvm-objcopy/ELF/Object.h
+++ llvm/tools/llvm-objcopy/ELF/Object.h
@@ -48,12 +48,12 @@
 struct Symbol;
 
 class SectionTableRef {
-  MutableArrayRef<std::unique_ptr<SectionBase>> Sections;
+  ArrayRef<std::unique_ptr<SectionBase>> Sections;
 
 public:
-  using iterator = pointee_iterator<std::unique_ptr<SectionBase> *>;
+  using iterator = pointee_iterator<const std::unique_ptr<SectionBase> *>;
 
-  explicit SectionTableRef(MutableArrayRef<std::unique_ptr<SectionBase>> Secs)
+  explicit SectionTableRef(ArrayRef<std::unique_ptr<SectionBase>> Secs)
       : Sections(Secs) {}
   SectionTableRef(const SectionTableRef &) = default;
 
@@ -1022,10 +1022,6 @@
   };
 
 public:
-  template <class T>
-  using Range = iterator_range<
-      pointee_iterator<typename std::vector<std::unique_ptr<T>>::iterator>>;
-
   template <class T>
   using ConstRange = iterator_range<pointee_iterator<
       typename std::vector<std::unique_ptr<T>>::const_iterator>>;
@@ -1055,10 +1051,7 @@
   SectionIndexSection *SectionIndexTable = nullptr;
 
   void sortSections();
-  SectionTableRef sections() { return SectionTableRef(Sections); }
-  ConstRange<SectionBase> sections() const {
-    return make_pointee_range(Sections);
-  }
+  SectionTableRef sections() const { return SectionTableRef(Sections); }
   iterator_range<
       filter_iterator<pointee_iterator<std::vector<SecPtr>::const_iterator>,
                       decltype(&sectionIsAlloc)>>
@@ -1073,7 +1066,6 @@
   }
   SectionTableRef removedSections() { return SectionTableRef(RemovedSections); }
 
-  Range<Segment> segments() { return make_pointee_range(Segments); }
   ConstRange<Segment> segments() const { return make_pointee_range(Segments); }
 
   Error removeSections(bool AllowBrokenLinks,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107652.364804.patch
Type: text/x-patch
Size: 1879 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210806/56d99aeb/attachment.bin>


More information about the llvm-commits mailing list