<div dir="ltr">yeah, sounds good to me (well, unique_ptr<uint8_t[]>, I guess)</div><br><div class="gmail_quote"><div dir="ltr">On Wed, Sep 6, 2017 at 3:01 PM Rafael Avila de Espindola <<a href="mailto:rafael.espindola@gmail.com">rafael.espindola@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Alternativelly it can also just be a std::unique_ptr<uint8_t>, no?<br>
<br>
Cheers,<br>
Rafael<br>
<br>
David Blaikie via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>> writes:<br>
<br>
> Is it really worth/necessary to indirect this vector through a unique_ptr?<br>
> Saves two words in the InputSection, I guess, in the common (not<br>
> compressed) case? (could save the other word too, if you used a separate<br>
> map to only store these things when needed)<br>
><br>
> But maybe this is the sweet spot of convenience and memory usage. Just<br>
> curious/checking :)<br>
><br>
> On Wed, Aug 16, 2017 at 5:28 PM Rui Ueyama via llvm-commits <<br>
> <a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>> wrote:<br>
><br>
>> Author: ruiu<br>
>> Date: Wed Aug 16 17:27:55 2017<br>
>> New Revision: 311056<br>
>><br>
>> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=311056&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=311056&view=rev</a><br>
>> Log:<br>
>> Remove a lock and use a std::unique_ptr instead.<br>
>><br>
>> We had a lock to guard BAlloc from being used concurrently, but that<br>
>> is not very easy to understand. This patch replaces it with a<br>
>> std::unique_ptr.<br>
>><br>
>> Modified:<br>
>>     lld/trunk/ELF/InputSection.cpp<br>
>>     lld/trunk/ELF/InputSection.h<br>
>><br>
>> Modified: lld/trunk/ELF/InputSection.cpp<br>
>> URL:<br>
>> <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=311056&r1=311055&r2=311056&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=311056&r1=311055&r2=311056&view=diff</a><br>
>><br>
>> ==============================================================================<br>
>> --- lld/trunk/ELF/InputSection.cpp (original)<br>
>> +++ lld/trunk/ELF/InputSection.cpp Wed Aug 16 17:27:55 2017<br>
>> @@ -200,17 +200,12 @@ void InputSectionBase::uncompress() {<br>
>>                                                  Config->IsLE,<br>
>> Config->Is64));<br>
>><br>
>>    size_t Size = Dec.getDecompressedSize();<br>
>> -  char *OutputBuf;<br>
>> -  {<br>
>> -    static std::mutex Mu;<br>
>> -    std::lock_guard<std::mutex> Lock(Mu);<br>
>> -    OutputBuf = BAlloc.Allocate<char>(Size);<br>
>> -  }<br>
>> -<br>
>> -  if (Error E = Dec.decompress({OutputBuf, Size}))<br>
>> +  UncompressBuf.reset(new std::vector<uint8_t>(Size));<br>
>> +  if (Error E = Dec.decompress({(char *)UncompressBuf->data(), Size}))<br>
>>      fatal(toString(this) +<br>
>>            ": decompress failed: " + llvm::toString(std::move(E)));<br>
>> -  this->Data = ArrayRef<uint8_t>((uint8_t *)OutputBuf, Size);<br>
>> +<br>
>> +  this->Data = *UncompressBuf;<br>
>>    this->Flags &= ~(uint64_t)SHF_COMPRESSED;<br>
>>  }<br>
>><br>
>><br>
>> Modified: lld/trunk/ELF/InputSection.h<br>
>> URL:<br>
>> <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.h?rev=311056&r1=311055&r2=311056&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.h?rev=311056&r1=311055&r2=311056&view=diff</a><br>
>><br>
>> ==============================================================================<br>
>> --- lld/trunk/ELF/InputSection.h (original)<br>
>> +++ lld/trunk/ELF/InputSection.h Wed Aug 16 17:27:55 2017<br>
>> @@ -183,6 +183,11 @@ public:<br>
>>      assert(S % sizeof(T) == 0);<br>
>>      return llvm::makeArrayRef<T>((const T *)Data.data(), S / sizeof(T));<br>
>>    }<br>
>> +<br>
>> +private:<br>
>> +  // A pointer that owns uncompressed data if a section is compressed by<br>
>> zlib.<br>
>> +  // Since the feature is not used often, this is usually a nullptr.<br>
>> +  std::unique_ptr<std::vector<uint8_t>> UncompressBuf;<br>
>>  };<br>
>><br>
>>  // SectionPiece represents a piece of splittable section contents.<br>
>><br>
>><br>
>> _______________________________________________<br>
>> llvm-commits mailing list<br>
>> <a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
>> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
>><br>
> _______________________________________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div>