<table><tr><td style="">ahmadsamir added inline comments.
</td><a style="text-decoration: none; padding: 4px 8px; margin: 0 8px 8px; float: right; color: #464C5C; font-weight: bold; border-radius: 3px; background-color: #F7F7F9; background-image: linear-gradient(to bottom,#fff,#f1f0f1); display: inline-block; border: 1px solid rgba(71,87,120,.2);" href="https://phabricator.kde.org/D25039">View Revision</a></tr></table><br /><div><strong>INLINE COMMENTS</strong><div><div style="margin: 6px 0 12px 0;"><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D25039#inline-141630">View Inline</a><span style="color: #4b4d51; font-weight: bold;">kossebau</span> wrote in <span style="color: #4b4d51; font-weight: bold;">ftp.cpp:1376</span></div>
<div style="margin: 8px 0; padding: 0 12px; color: #74777D;"><p style="padding: 0; margin: 8px;"><tt style="background: #ebebeb; font-size: 13px;">QUrl::fileName()</tt> returns a value QString, so just</p>

<div class="remarkup-code-block" style="margin: 12px 0;" data-code-lang="text" data-sigil="remarkup-code-block"><pre class="remarkup-code" style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; padding: 12px; margin: 0; background: rgba(71, 87, 120, 0.08);">const QString filename = empurl.fileName();</pre></div>

<p style="padding: 0; margin: 8px;">While</p>

<div class="remarkup-code-block" style="margin: 12px 0;" data-code-lang="text" data-sigil="remarkup-code-block"><pre class="remarkup-code" style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; padding: 12px; margin: 0; background: rgba(71, 87, 120, 0.08);">const QString &filename = empurl.fileName();</pre></div>

<p style="padding: 0; margin: 8px;">also is fine code IIRC, as I once learned to my surprise,  as the <tt style="background: #ebebeb; font-size: 13px;">const QString &</tt> here means to tell the compiler the actual value instance should be hold only until the last use of the variable, not the end of the scope in which the variable exists, this seems also not well known by others, so might only make them confuse.<br />
Given this is an optimization not needed here, IMHO no need to use this technique here.</p></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">IIUC, the compiler will use a temporary object to hold the return of tempurl.fileName().</p>

<p style="padding: 0; margin: 8px;">The temporary is used to initialize filename, and then it's gone:<br />
const QString filename = tempurl.filename();</p>

<p style="padding: 0; margin: 8px;">filename here is a reference-to-const to the temporary object and the temporary will have the same lifetime as the reference (for objects on the stack), so until the end of the scope:<br />
const QString &filename = tempurl.fileName();<br />
c.f. <a href="https://herbsutter.com/2008/01/01/gotw-88-a-candidate-for-the-most-important-const/" class="remarkup-link" target="_blank" rel="noreferrer">https://herbsutter.com/2008/01/01/gotw-88-a-candidate-for-the-most-important-const/</a></p>

<p style="padding: 0; margin: 8px;">In my mind it kind of makes more sense to use a reference-to-const when the rvalue (tempurl.fileName()) is not a temporary object, because I am saving nothing by using a reference here since the compiler will create the temporary object and hold it until the end of the scope anyway.</p>

<p style="padding: 0; margin: 8px;">In this particular case, it's probably exactly the same whether the temporary is used to initialize a const non-reference object and then (the temporary) is dropped/gone or the object being initialized is a reference to const to the temporary until the end of the scope...</p>

<p style="padding: 0; margin: 8px;">job->statResult() and job->url() are different because both of them return a reference to const.</p></div></div></div></div></div><br /><div><strong>REPOSITORY</strong><div><div>R241 KIO</div></div></div><br /><div><strong>REVISION DETAIL</strong><div><a href="https://phabricator.kde.org/D25039">https://phabricator.kde.org/D25039</a></div></div><br /><div><strong>To: </strong>meven, Frameworks, dfaure<br /><strong>Cc: </strong>ahmadsamir, anthonyfieroni, kossebau, kde-frameworks-devel, LeGast00n, GB_2, michaelh, ngraham, bruns<br /></div>