matrix.go: preallocate slice for String() method
To avoid slice growth with append operations.master
parent
2fde63d288
commit
7a64c70cbc
|
@ -87,9 +87,9 @@ func (m matrix) Check() error {
|
|||
//
|
||||
// Example: [[1, 2], [3, 4]]
|
||||
func (m matrix) String() string {
|
||||
var rowOut []string
|
||||
rowOut := make([]string, 0, len(m))
|
||||
for _, row := range m {
|
||||
var colOut []string
|
||||
colOut := make([]string, 0, len(row))
|
||||
for _, col := range row {
|
||||
colOut = append(colOut, strconv.Itoa(int(col)))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue