ctf: replace HashMaps with ArrayLists for EventDeclaration storage
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core / src / org / eclipse / linuxtools / internal / ctf / core / event / EventDeclaration.java
index 5e40f57458d8d55798806fe58d5d12de4732d8dd..7aa0976e7d05e8fd50381f18bf06a20693761c69 100644 (file)
@@ -61,11 +61,6 @@ public class EventDeclaration implements IEventDeclaration {
      */
     private StructDeclaration fFields = null;
 
-    /**
-     * Event id (can be null if only event in the stream).
-     */
-    private Long fId = UNSET_EVENT_ID;
-
     /**
      * Stream to which belongs this event.
      */
@@ -79,6 +74,8 @@ public class EventDeclaration implements IEventDeclaration {
     /** Map of this event type's custom CTF attributes */
     private final Map<String, String> fCustomAttributes = new HashMap<>();
 
+    private int fId = (int) UNSET_EVENT_ID;
+
     // ------------------------------------------------------------------------
     // Constructors
     // ------------------------------------------------------------------------
@@ -122,7 +119,7 @@ public class EventDeclaration implements IEventDeclaration {
         String[] fieldNames = new String[] { CTFStrings.LOST_EVENTS_FIELD, CTFStrings.LOST_EVENTS_DURATION };
         Declaration[] fieldDeclarations = new Declaration[] { IntegerDeclaration.UINT_32B_DECL, IntegerDeclaration.UINT_64B_DECL };
         lostEvent.fFields = new StructDeclaration(fieldNames, fieldDeclarations);
-        lostEvent.fId = LOST_EVENT_ID;
+        lostEvent.fId = (int) LOST_EVENT_ID;
         lostEvent.fName = CTFStrings.LOST_EVENT_NAME;
         return lostEvent;
     }
@@ -183,11 +180,23 @@ public class EventDeclaration implements IEventDeclaration {
      *            the id
      */
     public void setId(long id) {
-        fId = id;
+        if (id < 0 || id > Integer.MAX_VALUE) {
+            throw new IllegalArgumentException("id out of range"); //$NON-NLS-1$
+        }
+        fId = (int) id;
     }
 
     @Override
     public Long getId() {
+        return Long.valueOf(fId);
+    }
+
+    /**
+     * Faster get id assuming you have less than a billion event types
+     *
+     * @return the event id
+     */
+    public int id() {
         return fId;
     }
 
@@ -240,7 +249,7 @@ public class EventDeclaration implements IEventDeclaration {
      * @return is the id set?
      */
     public boolean idIsSet() {
-        return (fId != null && fId != UNSET_EVENT_ID);
+        return (fId  != UNSET_EVENT_ID);
     }
 
     /**
@@ -320,11 +329,7 @@ public class EventDeclaration implements IEventDeclaration {
         } else if (!fFields.equals(other.fFields)) {
             return false;
         }
-        if (fId == null) {
-            if (other.fId != null) {
-                return false;
-            }
-        } else if (!fId.equals(other.fId)) {
+        if (fId != (other.fId)) {
             return false;
         }
         if (fName == null) {
@@ -354,7 +359,7 @@ public class EventDeclaration implements IEventDeclaration {
         result = (prime * result)
                 + ((fContext == null) ? 0 : fContext.hashCode());
         result = (prime * result) + ((fFields == null) ? 0 : fFields.hashCode());
-        result = (prime * result) + ((fId == null) ? 0 : fId.hashCode());
+        result = (prime * result) + fId;
         result = (prime * result) + ((fName == null) ? 0 : fName.hashCode());
         result = (prime * result) + ((fStream == null) ? 0 : fStream.hashCode());
         result = (prime * result) + fCustomAttributes.hashCode();
This page took 0.024606 seconds and 5 git commands to generate.