Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Search instead for 
Did you mean: 
EnTerr
Level 8

Caveat: ss.AppendString(s, len(s)) no better than ss=ss+s ?

roString has the mutator AppendString(), which i assumed is there for performance reasons, to allow building a string much faster by repeatedly appending text at the end, through expanding the original buffer instead of creating new object through concatenation every time. Or at least so i know from other languages. But that does not seem to be the case:
BrightScript Debugger> ti = createObject("roTimespan")
BrightScript Debugger> s = string(1000, "x")
BrightScript Debugger> ss = "1"+"2": ti.mark(): for k=1 to 1000: ss=ss+s: end for: ? ti.totalMilliseconds()
14290
BrightScript Debugger> ss = "1"+"2": ti.mark(): for k=1 to 1000: ss.appendString(s, len(s)): end for: ? ti.totalMilliseconds()
14461

So if anything, appendString() is marginally slower (i suspect because of price of method lookup and two function calls). My take out will be not to use it then. Any insight what's the purpose of the method if not speed?
0 Kudos
1 Reply
EnTerr
Level 8

Bonus: bugs in AppendString()

I also ran into 2-3 bugs in AppendString implementation on fw3:
BrightScript Debugger> s = "1" + "2"
BrightScript Debugger> s.appendString("3", 999999999): ? s 'should be 123
12
BrightScript Debugger> s.appendString(s, len(s)): ? s 'should be 1212
12
And there was something else while i played with boxing the value after seeing it wouldn't append self to itself... something darker that ended up adding random characters and ultimately led to YAWRR crash. But i cannot reproduce it now so will leave it at "hearsay" level
0 Kudos