At the
end of the day, the only way to make it faster is to pre-allocate the result
string, and then treat it as a buffer using pchar's - I use this method quite
often.
Your
function is quite good, but still results in ItemCount string allocations -
hence ItemCount calls to the memory manager - which is the slow part in using
dynamic (long) strings.
You
could probably make the assumption in dealing with sql column names, that each
name could take upto 32 characters (Max 31 plus coma), then double just to be
safe, eg Setlength( S, ItemCount*64) And on exit just make the length shorter by
using SetLength again.
Also
you dont want to make multiple function calls, so call Sep once and store it in
a local variable, and of course if you know that it will be only 1 or 2 chars
long, you could use a Character array stored locally on stack instead - again
avoiding memory manager calls.
Given
that you are doing a simple concat, using Format is a bit of overkill - it does
execute a lot of code and so does take some time. You might even find doing S :=
S + ',' + Item(i) might be faster - as of course mentioned yesterday, execute
your method several million times and see how long different versions take - at
the end of the day it is the best (only?) real test.
Myles.
|
- [DUG]: RichEdit - How can I select text from po... gajo
- [DUG]: Quicky - the registry Alistair George
- RE: [DUG]: Quicky - the registry Andreas Toth
- Re[2]: [DUG]: Quicky - the registr... Alistair George
- RE: Re[2]: [DUG]: Quicky - the... Andreas Toth
- [DUG]: Quicky - the registry Alistair George
- [DUG]: Debugging DLL Phil Middlemiss
- RE: [DUG]: Debugging DLL Allan Vergara
- Re[2]: [DUG]: Quicky - the registr... Alistair George
- RE: [DUG]: Friday Challenge Leigh Wanstead
- RE: [DUG]: Friday Challange Myles Penlington
- RE: [DUG]: Friday Challange Stephen Bertram
- Re: [DUG]: Friday Challange Tracey Maule
- Re: [DUG]: Friday Challange Neven MacEwan
- Re: [DUG]: Friday Challange James Sugrue
- Re: [DUG]: Friday Challange Kurt at iadvance
- Re: [DUG]: Friday Challange James Sugrue
- Re: [DUG]: Friday Challange Tracey Maule
- Re: [DUG]: Friday Challange James Sugrue
- RE: [DUG]: Friday Challange Conor Boyd