From dfcc2729d16b8585f46edc4dbbc860d9c7178244 Mon Sep 17 00:00:00 2001 From: Matthew Khouzam Date: Mon, 30 Sep 2024 08:48:17 -0400 Subject: [PATCH] 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 --- .../ctf/core/event/types/EnumDefinition.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/EnumDefinition.java b/ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/EnumDefinition.java index 18c2bdd830..bc7f67708a 100644 --- a/ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/EnumDefinition.java +++ b/ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/EnumDefinition.java @@ -36,9 +36,11 @@ public final class EnumDefinition extends SimpleDatatypeDefinition { private static final String UNKNOWN_ENUM = " (%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 @@ -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; + } // ------------------------------------------------------------------------ @@ -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()); }