Skip to content

Enum Array Literal Check

Hackerpilot edited this page Nov 13, 2014 · 1 revision

Config attribute name

enum_array_literal_check

Description

Checks for array literals declared enum in class and struct declarations. These lead to large amounts of run-time memory allocation.

Example

Code

The runtime will allocate a copy of this array literal every time it is used.

struct SomeStruct {
    enum VALUES = [1, 2, 3, 4, 5];
}

Suggested fix

Use static immutable instead.

struct SomeStruct {
    static immutable VALUES = [1, 2, 3, 4, 5];
}
Clone this wiki locally