if there are other circumstances where the length poses an issue requiring a fix I'd look at using the msb of the length to mark a string as dirty so the internal len function can fallback to scan and reset it.
so when passing a string to a function as **str flag it dirty, or is set with space() flag it dirty.
The question is would it introduce undesired side effects? It also adds the cost of a branch and needs atomics to do it thread safe. It's a lot of work for not a real problem but it would providing backward compatibility.
A lot of users rely on s.s= space(#maxpath) for windows api even though it's technically wrong and doubly so without using the returned length from the api, it just happens to work on windows.
The main issues with the speed of PB string processing has always been due to how it appends a string in a loop.
which isn't such an easy fix from the compiler perspective, it could be fixed by either look ahead and back tracing, deferred where you build two blocks at the same time and choose the block at closure or subsequent use of the string within the block or as a post generation peephole parse. Deferred is probably the better option to bolt on but its still not so easy to do.
PB 6.30 c backend, what you get vs what you want and there is no optimization parse in gcc that could fix it either that I'm aware of. So use the stringbuilder going forward or offer Fred $$$ to suffer the torment, pain and gnashing of teeth to implementing a compiler parse to fix it.
Code: Select all
Global s1.s
Global s2.s
Global l1,l2
s1 = "hello"
s2 = "world"
st = ElapsedMilliseconds()
For a =0 To 10000 ;s1+s2 blows out copying s1
!SYS_PushStringBasePosition();
!SYS_CopyString(g_s1);
!SYS_CopyString(g_s2);
!SYS_AllocateString4(&g_s1,SYS_PopStringBasePosition());
Next
et = ElapsedMilliseconds()
l1 = Len(s1)
s1 = "hello"
s2 = "world"
st1 = ElapsedMilliseconds()
!SYS_PushStringBasePosition(); s1+2s doesn't blow out copying s1
For a = 0 To 10000
!SYS_CopyString(g_s2);
Next
!SYS_CopyString(g_s2);
!SYS_AllocateString4(&g_s1,SYS_PopStringBasePosition());
et1 = ElapsedMilliseconds()
l2 = Len(s1)
out.s = Str(et-st) + " " + Str(et1-st1) + " " + Str(l1) + " " + Str(l2)
MessageRequester("test",out)
At least We have the Stringbuilder option to mitigate it, though it would be great if it could be addressed in the compiler itself one day.