[PATCH] D52917: Avoid unnecessary buffer allocation and memcpy for compressed sections.

Rui Ueyama via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 5 10:38:41 PDT 2018


ruiu added inline comments.


================
Comment at: lld/ELF/InputSection.cpp:155
+  if (UncompressedSize >= 0 && !UncompressedBuf)
+    const_cast<InputSectionBase *>(this)->uncompress();
+  return RawData;
----------------
dblaikie wrote:
> ruiu wrote:
> > MaskRay wrote:
> > > It seems `uncompress()` is only called once. What do you think if `uncompress()` is inlined here and these mutable member variables are marked as `mutable`?
> > > 
> > I could, but I'm not sure if it is a good thing to mark `RawData` and `UncompressedBuf` mutable throughout this class. At least in this way, only this function mutates these members.
> Personally I'd vote for using mutable - using const_cast places a "spooky action at a distance" to the use of this type (it means you can't make a const instance of this type if you use this function - because const_casting away const on an actually const object is UB). While that might not be an issue in this particular class (it might be quite unlikely anyone would make a const instance of this type) - I'd still lean that way out of stylistic consistency with other use cases, etc.
> 
> Not a huge deal, though.
I don't have a strong opinion, so I changed the code to not use `const_cast` but `mutable`.



https://reviews.llvm.org/D52917





More information about the llvm-commits mailing list