Skip to content

Commit

Permalink
ctf: lazy format the enums
Browse files Browse the repository at this point in the history
With larger enums, this can provide a significant performance boost

[Changed] Lazy format enums in CTF

Change-Id: Icb85752a6b05cf2df0bef9ac322582035c1ff029
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
  • Loading branch information
MatthewKhouzam committed Sep 30, 2024
1 parent 945b92e commit dfcc272
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ public final class EnumDefinition extends SimpleDatatypeDefinition {

private static final String UNKNOWN_ENUM = "<unknown> (%s)"; //$NON-NLS-1$

private static final String UNINITIALIZED = "UNINITIALIZED"; //$NON-NLS-1$

private final IntegerDefinition fInteger;

private final @Nullable String fValue;
private @Nullable String fValue;

// ------------------------------------------------------------------------
// Constructors
Expand All @@ -59,9 +61,9 @@ public final class EnumDefinition extends SimpleDatatypeDefinition {
public EnumDefinition(@NonNull EnumDeclaration declaration,
IDefinitionScope definitionScope, @NonNull String fieldName, IntegerDefinition intValue) {
super(declaration, definitionScope, fieldName);

fInteger = intValue;
fValue = declaration.query(fInteger.getValue());
fValue = UNINITIALIZED;

}

// ------------------------------------------------------------------------
Expand All @@ -75,6 +77,9 @@ public EnumDefinition(@NonNull EnumDeclaration declaration,
* @return the value of the enum.
*/
public String getValue() {
if (fValue == UNINITIALIZED) {
fValue = getDeclaration().query(fInteger.getValue());
}
return fValue != null ? fValue : String.format(UNKNOWN_ENUM, getIntegerValue());
}

Expand Down

0 comments on commit dfcc272

Please sign in to comment.