<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body smarttemplateinserted="true">
<div id="smartTemplate4-template">Hi,</div>
<div><br>
</div>
<div>and why is it not inlining the count and append call of this
string builder? It is not using any implementation only function<br>
<p>unit inlinetest;<br>
<br>
{$mode objfpc}{$H+}<br>
<br>
interface<br>
<br>
uses<br>
Classes, SysUtils,math;<br>
<br>
type TStrBuilder = object<br>
protected<br>
next, bufferend: pchar; //next empty pchar and first pos after
the string<br>
public<br>
buffer: pstring;<br>
procedure init(abuffer:pstring);<br>
procedure final;<br>
function count: SizeInt; inline;<br>
procedure reserveadd(delta: SizeInt);<br>
procedure append(c: char); inline;<br>
procedure append(const s: RawByteString); inline;<br>
procedure append(const p: pchar; const l: SizeInt); inline;<br>
end;<br>
<br>
implementation<br>
<br>
procedure TStrBuilder.init(abuffer: pstring);<br>
begin<br>
buffer := abuffer;<br>
SetLength(buffer^, 16); //use setlength to create a new string<br>
<br>
next := pchar(buffer^);<br>
bufferend := next + length(buffer^);<br>
end;<br>
<br>
procedure TStrBuilder.final;<br>
begin<br>
if next <> bufferend then begin<br>
setlength(buffer^, count); // !!! Note: Call to subroutine
"function TStrBuilder.count:Int64;" marked as inline is not
inlined<br>
next := pchar(buffer^) + length(buffer^);<br>
bufferend := next;<br>
end;<br>
end;<br>
<br>
function TStrBuilder.count: SizeInt;<br>
begin<br>
result := next - pointer(buffer^);<br>
end;<br>
<br>
<br>
procedure TStrBuilder.reserveadd(delta: SizeInt);<br>
var<br>
oldlen: SizeInt;<br>
begin<br>
if next + delta > bufferend then begin<br>
oldlen := count;<br>
SetLength(buffer^, max(2*length(buffer^), oldlen + delta));<br>
next := pchar(buffer^) + oldlen;<br>
bufferend := pchar(buffer^) + length(buffer^);<br>
end;<br>
end;<br>
<br>
procedure TStrBuilder.append(c: char);<br>
begin<br>
if next >= bufferend then reserveadd(1);<br>
next^ := c;<br>
inc(next);<br>
end;<br>
<br>
procedure TStrBuilder.append(const s: RawByteString);<br>
begin<br>
append(pchar(pointer(s)), length(s)); // !!!
inlinetest.pas(71,3) Note: Call to subroutine "procedure
TStrBuilder.append(const p:PChar;const l:Int64);" marked as
inline is not inlined<br>
end;<br>
<br>
<br>
<br>
procedure TStrBuilder.append(const p: pchar; const l: SizeInt);
inline;<br>
begin<br>
if l <= 0 then exit;<br>
if next + l > bufferend then reserveadd(l);<br>
move(p^, next^, l);<br>
inc(next, l);<br>
end;<br>
<br>
<br>
<br>
end.<br>
<br>
</p>
<br>
<br>
Bye,<br>
Benito </div>
<br>
<div class="moz-cite-prefix">Am 29.12.18 um 20:31 schrieb Sven Barth
via fpc-pascal:<br>
</div>
<blockquote type="cite"
cite="mid:CAFMUeB9RSJyMA8B4-H=F6iCbOsmn92uRqLicS3NovaJyRP1O1w@mail.gmail.com">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<div dir="auto">
<div class="gmail_quote" dir="auto">
<div dir="ltr">Am Sa., 29. Dez. 2018, 15:23 hat Benito van der
Zander <<a href="mailto:benito@benibela.de"
moz-do-not-send="true">benito@benibela.de</a>>
geschrieben:<br>
</div>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
after updating from fpc 3.1 to fpc 3.3, I am getting a lot
of "function <br>
was not inlined" warnings, e.g. when an inline function
depends on a <br>
function not declared in the interface part like:<br>
<br>
unit inlinetest;<br>
<br>
{$mode objfpc}{$H+}<br>
<br>
interface<br>
<br>
uses<br>
Classes, SysUtils;<br>
<br>
<br>
function strContains(const str, searched: string): boolean;
inline;<br>
<br>
implementation<br>
<br>
function strContainsFrom(const str, searched: string; from:
SizeInt): <br>
boolean;<br>
begin<br>
result:=Pos(searched, str, from) > 0;<br>
end;<br>
<br>
<br>
function strContains(const str, searched: string): boolean;
inline;<br>
begin<br>
result := strContainsFrom(str, searched, 1);<br>
end;<br>
<br>
end.<br>
<br>
<br>
<br>
Is that supposed to happen?<br>
<br>
Fpc 3.1 did not show any warning in this case (although now
that I <br>
investigate it, fpc 3.1 also did not seem to inline it
despite not <br>
showing the warning)<br>
</blockquote>
</div>
<div dir="auto"><br>
</div>
<div dir="auto">Correct. FPC 3.1.1 did neither warn nor inline
in this case, 3.3.1 at least warns (I think 3.2 already warns
as well). </div>
<div dir="auto"><br>
</div>
<div dir="auto">Regards, </div>
<div dir="auto">Sven </div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
fpc-pascal maillist - <a class="moz-txt-link-abbreviated" href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a>
<a class="moz-txt-link-freetext" href="http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal">http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal</a></pre>
</blockquote>
</body>
</html>