Skip to content

Commit d8dde9c

Browse files
ctf: lazy format the enums
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>
1 parent c87c2c8 commit d8dde9c

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

  • ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types

ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/EnumDefinition.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ public final class EnumDefinition extends SimpleDatatypeDefinition {
3636

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

39+
private static final String UNINITIALIZED = "UNINITIALIZED"; //$NON-NLS-1$
40+
3941
private final IntegerDefinition fInteger;
4042

41-
private final @Nullable String fValue;
43+
private @Nullable String fValue;
4244

4345
// ------------------------------------------------------------------------
4446
// Constructors
@@ -59,9 +61,9 @@ public final class EnumDefinition extends SimpleDatatypeDefinition {
5961
public EnumDefinition(@NonNull EnumDeclaration declaration,
6062
IDefinitionScope definitionScope, @NonNull String fieldName, IntegerDefinition intValue) {
6163
super(declaration, definitionScope, fieldName);
62-
6364
fInteger = intValue;
64-
fValue = declaration.query(fInteger.getValue());
65+
fValue = UNINITIALIZED;
66+
6567
}
6668

6769
// ------------------------------------------------------------------------
@@ -75,6 +77,9 @@ public EnumDefinition(@NonNull EnumDeclaration declaration,
7577
* @return the value of the enum.
7678
*/
7779
public String getValue() {
80+
if (fValue == UNINITIALIZED) {
81+
fValue = getDeclaration().query(fInteger.getValue());
82+
}
7883
return fValue != null ? fValue : String.format(UNKNOWN_ENUM, getIntegerValue());
7984
}
8085

0 commit comments

Comments
 (0)