Testing "binary cut" of strings (manually placing a terminating zero with size of short
Code: Select all
s1:=s "." ;+1 symbol
NumPut(0,s1,(StrLen(s1)-2)*2,"short") ;-2 symbols
VarSetCapacity(s1,-1) ;force AHK to recalculate length
s2:=SubStr(s1,1,-2) ;regular substringing to cut 2 symbols from the end
msgbox(clipboard:=a1 "|" a2 "`n`n" s1)
Sometimes its a tad slower, but for the most part its up to 30%
faster for long strings.
I use the same 14KB json test file here:
For a string 10 symbols long, the regular SubStr
is x1.5 .. x2 as fast.
So for truncating a loaded text file I would use "a binary cut" for sure =) I wish AHK would have a function StrTrunc or something just to quickly reduce a string's length
Actually thats the exact time where we could use super fast mcode of SSE4.2-boosted Strlen
. But I dont know where to put that number so that AHK would accept it as a string length.