I have some cases in my code where I am building a large line of text, such as a complex SQL statement. I intend to combine this text many times in a row, each of which has several slightly different parameters. I'm used to using a routine called just procedure A(const S: String); , which simply adds text ( S ) to the larger line Text := Text + S + #10 + #13;
I was wondering if this could hinder performance rather than using traditional string concatenation? I'm starting to think that the compiler is optimizing something like this:
Text := 'some' + ' ' + 'text' + ' ' + 'and' + ' ' + 'such';
to
Text := 'some text and such';
It's true? Does this scenario optimize this scenario? If so, I can change everything to something like this:
Text := 'select something from sometable st'+#10+#13+ 'join someothertable sot on sot.id = st.sotid'+#10+#13+ 'where sot.somevalue = 1'+#10+#13+ 'order by sot.sorting';
It would be faster theoretically than
Text:= Text + 'select something from sometable st'+#10+#13; Text:= Text + 'join someothertable sot on sot.id = st.sotid'+#10+#13; Text:= Text + 'where sot.somevalue = 1'+#10+#13; Text:= Text + 'order by sot.sorting';
or as usual I do it:
A('select something from sometable st'); A('join someothertable sot on sot.id = st.sotid'); A('where sot.somevalue = 1'); A('order by sot.sorting');
source share