Open KieranP opened 1 month ago
For string concatenation, navi is optimized internally and does not need to copy the entire string, so StringBuilder is not needed.
@sunli829 Ok, thank you. Is there a more efficient way to do this then?
let rendering: [string] = [];
for (let y in 0..self.height) {
for (let x in 0..self.width) {
let cell = self.cell_at(x, y);
if (!cell.is_nil()) {
rendering.push(cell!.to_char().to_string());
}
}
rendering.push("\n");
}
return rendering.join("");
I have a Cell struct, with a to_char() method. It returns a char
. But because there is no such thing as [Char].join()
(it only works with [String].join()
, I have to call to_string() on each char within the loop, which I think might be slowing things down? Any thoughts?
I will add [char].join()
method
A way to efficiently build strings. Current options include concatening string or building string array and calling
join('')
, neither of which is performant:C#
C++
GoLang: