Open GWRon opened 4 years ago
Since arrays are mutable and nothing is stopping you from doing ETest.Values()[0] = 123
, you'd be able to break the array for future .Value()
calls. To prevent that, it needs to create a new array.
My suggestion is that once generics support is more complete, .Value()
could be changed to return an IIterable
instead. Then it will no longer be necessary to create copies of the backing array, as long as you only want to read/iterate the values.
Until then you could store the array in a Global
somewhere if the performance worries you.
Isn't
Values()
here creating a new array each time?the generated C code contains:
brl.mod/blitz.mod/blitz_enum.c defines the
bbEnumValues()
function this way:Now my questions: while this not a biggy (dunno who would call it the way I do in my sample) I thought enums are kind of "constant" - so the returned "Values()"-array could be created right during compilation already - or not?
Is this not done to save memory (only create if needed) or are enums not really constant? Is this to ensure that (the returned) arrays are not manipulated for future calls to it?