<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Nov 20, 2014 at 2:49 PM, David Blaikie <span dir="ltr"><<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Thu, Nov 20, 2014 at 2:48 PM, Sean Silva <span dir="ltr"><<a href="mailto:chisophugis@gmail.com" target="_blank">chisophugis@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><div><div>On Thu, Nov 20, 2014 at 2:39 PM, David Blaikie <span dir="ltr"><<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><div><div>On Thu, Nov 20, 2014 at 2:39 PM, Sean Silva <span dir="ltr"><<a href="mailto:chisophugis@gmail.com" target="_blank">chisophugis@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><div><div>On Thu, Nov 20, 2014 at 1:46 PM, David Blaikie <span dir="ltr"><<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span>On Thu, Nov 20, 2014 at 1:19 PM, Nick Kledzik <span dir="ltr"><<a href="mailto:kledzik@apple.com" target="_blank">kledzik@apple.com</a>></span> wrote:<br></span><span><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Author: kledzik<br>
Date: Thu Nov 20 15:19:58 2014<br>
New Revision: 222455<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=222455&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=222455&view=rev</a><br>
Log:<br>
[mach-o] use reference with "auto" to prevent copies<br>
<br>
Patch by Jean-Daniel Dupas<br>
<br>
Modified:<br>
lld/trunk/lib/ReaderWriter/MachO/File.h<br>
<br>
Modified: lld/trunk/lib/ReaderWriter/MachO/File.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/File.h?rev=222455&r1=222454&r2=222455&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/File.h?rev=222455&r1=222454&r2=222455&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/lib/ReaderWriter/MachO/File.h (original)<br>
+++ lld/trunk/lib/ReaderWriter/MachO/File.h Thu Nov 20 15:19:58 2014<br>
@@ -118,13 +118,13 @@ public:<br>
MachODefinedAtom *findAtomCoveringAddress(const Section §ion,<br>
uint64_t offsetInSect,<br>
uint32_t *foundOffsetAtom=nullptr) {<br>
- auto pos = _sectionAtoms.find(§ion);<br>
+ const auto& pos = _sectionAtoms.find(§ion);<br></blockquote></span><div><br>This one's a bit weird - 'find' (for any standard-like container, at least) returns an iterator by value. While taking a reference to that is valid (reference lifetime extension & all that) it's a bit surprising & unnecessary (has basically the same semantics as the non-reference code).<br> </div><span><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
if (pos == _sectionAtoms.end())<br>
return nullptr;<br>
- auto vec = pos->second;<br>
+ const auto& vec = pos->second;<br>
assert(offsetInSect < section.content.size());<br>
// Vector of atoms for section are already sorted, so do binary search.<br>
- auto atomPos = std::lower_bound(vec.begin(), vec.end(), offsetInSect,<br>
+ const auto& atomPos = std::lower_bound(vec.begin(), vec.end(), offsetInSect,<br></blockquote><div><br></div></span><div>Same here, lower_bound just returns an iterator by value, this doesn't look like it's avoiding any copies.</div></div></div></div></blockquote><div><br></div></div></div><div>Also, wouldn't this create a reference to a temporary?</div></div></div></div></blockquote></div></div><div><br>Right - but reference extension semantics mean this isn't actually incorrect/unsafe... <br></div></div></div></div></blockquote><div><br></div></div></div><div>"<span style="font-family:arial,sans-serif;font-size:13px">reference extension semantics" doesn't ring a bell. Do you have a link to a (no pun intended) reference? (or could you briefly explain?)</span></div></div></div></div></blockquote></div></div><div><br>Taking a pseudorandom document from the Internet: <a href="http://herbsutter.com/2008/01/01/gotw-88-a-candidate-for-the-most-important-const/" target="_blank">http://herbsutter.com/2008/01/01/gotw-88-a-candidate-for-the-most-important-const/</a><br> </div></div></div></div></blockquote><div><br></div><div>Interesting. I guess that's one small class of bug that won't happen anymore.</div><div><br></div><div>-- Sean Silva</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span><font color="#888888"><div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><div><span style="font-family:arial,sans-serif;font-size:13px">-- Sean Silva</span></div></font></span><span><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div> </div><span><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span><font color="#888888"><div><br></div><div>-- Sean Silva</div></font></span><span><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
[offsetInSect](const SectionOffsetAndAtom &ao,<br>
uint64_t targetAddr) -> bool {<br>
// Each atom has a start offset of its slice of the<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></span></div><br></div></div>
<br>_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
<br></blockquote></span></div><br></div></div>
</blockquote></span></div><br></div></div>
</blockquote></span></div><br></div></div>
</blockquote></span></div><br></div></div>
</blockquote></div><br></div></div>