StringField() is not optimized for speed. PureBasic needs a fast pointer-to-pointer based function to extract fields from string, e.g. StringToken(@*PointerToString, Delimeter.s).
Another thing: Implementing my own version of such a function, I noticed that PureBasic lacks a Pointer structure:
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
REALbasic has Split() and Join() which convert delimited strings to and from an array.
If you have a very long delimited string this works much faster than PureBasics StringField() and REALbasic usually get's a kicking in speed comparisons with PB.
I'd like to see Split() and Join() implemented in PB.
Trond wrote:StringField() already works like that behind the scenes.
If that was true, my StringToken() would not be lightning faster than StringField() for parsing text files stored in a string buffer. What is killing StringField() is that it needs/uses that index argument...
Stringfield searches allways up the begin, thats slows it down
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Trond wrote:StringField() already works like that behind the scenes.
If that was true, my StringToken() would not be lightning faster than StringField() for parsing text files stored in a string buffer. What is killing StringField() is that it needs/uses that index argument...
Yes, the slowdown comes from the index. What you suggested that I said that PB already does is to pass a pointer to the string instead of copying in the string.
To Trond:
I said "pointer-to-pointer of string", like what CopyMemoryString() does.
To the.weavster:
Coming to PB from Python, at first I found myself uncomfortable with the lack of functions like Split() and Join(). Now that I have adjasted to the ways of PB, I can say I produce better code without Split() and Join(). Anyway, I have written efficient StringToList() and ListToString() procedures. If you want them to appear someware e.g. in "Tricks 'n' Tips" or be sent to you by PM, tell me.
the.weavster wrote:REALbasic has Split() and Join() which convert delimited strings to and from an array.
If you have a very long delimited string this works much faster than PureBasics StringField() and REALbasic usually get's a kicking in speed comparisons with PB.
I'd like to see Split() and Join() implemented in PB.
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
ImportC "msvcrt.lib"
CompilerIf #PB_Compiler_Unicode
strtok(*string,*seps) As "_wcstok"
CompilerElse
strtok(*string,*seps) As "_strtok"
CompilerEndIf
EndImport
string.s = "StringField() is not optimized for speed."
string + " PureBasic needs a fast pointer-to-pointer based function to extract fields from string, e.g. StringToken(@*PointerToString,Delimeter.s)."
Seps.s = " .(),@"
Token = strtok(@string,@Seps)
While Token
Debug PeekS(Token)
Token = strtok(#Null,@Seps)
Wend