useless_resizable
Finds a local [..] T that is only filled with a known number of array_add calls and never resized.
Category perf, warn by default.
#import "Basic";
main :: () {
parts: [..] string;
defer array_free(parts);
array_add(*parts, "a");
array_add(*parts, "b");
for parts print("%\n", it);
}warning[useless_resizable]: `parts` is a resizable array that only ever holds 2 elements
--> example.jai:4:5
|
4 | parts: [..] string;
| ^^^^^
|
= help: a fixed array does not allocate: `parts: [2] string;`, and the call that frees it goes away
= note: `useless_resizable` is `warn` by default#import "Basic";
main :: () {
parts := string.["a", "b"];
for parts print("%\n", it);
}A resizable array allocates and has to be freed; a handful of elements known up front fit in a fixed array on the stack (parts: [2] string).