[fpc-pascal] string concatenation speed
leonhard.holz at web.de
Tue Jun 21 21:19:53 CEST 2005
> if (sl <> '') then
> if ((sl = '"') AND (sl[length(sl)] = '"'))
> then BaseColor := copy(sl,2,length(sl)-2) else BaseColor :=
You can tweak this a little by storing sl and length(sl) in local
vars, but the whole approach tends to be slow. If you want it faster,
dont allocate memory ("copy" & ":=" on the stack) and dont move string
data. This could be done by "translating" BaseColor to an int or so.
Either case you should not to use the StringList - read out BaseColor
(and the other fields) directly from the source, skipping the " at reading.
> Another snippet esecially for concatenation is this:
> result := IntToStr(ID) + SEP +
> IntToStr(ID_Customer) + SEP +
> QT + Treatment + QT + SEP +
> DateToStr(Date) + SEP +
> QT + BaseColor + QT + SEP +
> ... and so on for approx. 15 fields
Same as above - try to avoid the concatenation. What do you do with
result? If you write it to a file, write it directly. If you echo it
somewhere, echo it directly. If you pass it to another function, make it
a record with pointers to the string data.
More information about the fpc-pascal