<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">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><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 &section,<br>
                                             uint64_t offsetInSect,<br>
                                             uint32_t *foundOffsetAtom=nullptr) {<br>
-    auto pos = _sectionAtoms.find(&section);<br>
+    const auto& pos = _sectionAtoms.find(&section);<br></blockquote><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><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><div>Same here, lower_bound just returns an iterator by value, this doesn't look like it's avoiding any copies.</div><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></div><br></div></div>