Raku equivalent of Java StringBuffer/StringBuilder?

Viewed 105

I need to create a big string out of a complex structure and the runtime is way too long. Back in the Java times I solved similar problems using StringBuffer or StringBuilder which greatly reduce the number of intermediate String objects needed.

Is there something similar in Raku?

1 Answers

Native string arrays pretty much allow you to do that.

my str @parts;
@parts.push("foo")
...
say @parts.join;

Is that what you're looking for?

Additionally: on the MoarVM backend, when you concat strings, they are not actually concatenated in memory, but rather just "linked" together into a single virtual string. Unfortunately, the moment you want to do a regular expression on a string, if does need to be flattened. Which is one of the reasons regular expressions are relatively expensive.

Related