changeset 9300:d73ad771a602

return immutable collections from (some) CompilationResult getters
author Doug Simon <doug.simon@oracle.com>
date Thu, 25 Apr 2013 17:45:44 +0200
parents 90ee20fd2c05
children ba441e21796f
files graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CompilationResult.java
diffstat 1 files changed, 24 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CompilationResult.java	Thu Apr 25 16:57:09 2013 +0200
+++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CompilationResult.java	Thu Apr 25 17:45:44 2013 +0200
@@ -22,6 +22,8 @@
  */
 package com.oracle.graal.api.code;
 
+import static java.util.Collections.*;
+
 import java.io.*;
 import java.util.*;
 
@@ -366,7 +368,7 @@
      */
     public void recordDataReference(int codePos, Constant data, int alignment, boolean inlined) {
         assert codePos >= 0 && data != null;
-        getDataReferences().add(new DataPatch(codePos, data, alignment, inlined));
+        dataReferences.add(new DataPatch(codePos, data, alignment, inlined));
     }
 
     /**
@@ -390,7 +392,7 @@
      * @param handlerPos the position of the handler
      */
     public void recordExceptionHandler(int codePos, int handlerPos) {
-        getExceptionHandlers().add(new ExceptionHandler(codePos, handlerPos));
+        exceptionHandlers.add(new ExceptionHandler(codePos, handlerPos));
     }
 
     /**
@@ -405,11 +407,11 @@
 
     private void addInfopoint(Infopoint infopoint) {
         // The infopoints list must always be sorted
-        if (!getInfopoints().isEmpty() && getInfopoints().get(getInfopoints().size() - 1).pcOffset >= infopoint.pcOffset) {
+        if (!infopoints.isEmpty() && infopoints.get(infopoints.size() - 1).pcOffset >= infopoint.pcOffset) {
             // This re-sorting should be very rare
-            Collections.sort(getInfopoints());
+            Collections.sort(infopoints);
         }
-        getInfopoints().add(infopoint);
+        infopoints.add(infopoint);
     }
 
     /**
@@ -421,7 +423,7 @@
      */
     public Mark recordMark(int codePos, Object id, Mark[] references) {
         Mark mark = new Mark(codePos, id, references);
-        getMarks().add(mark);
+        marks.add(mark);
         return mark;
     }
 
@@ -528,27 +530,39 @@
      * @return the list of infopoints, sorted by {@link Site#pcOffset}
      */
     public List<Infopoint> getInfopoints() {
-        return infopoints;
+        if (infopoints.isEmpty()) {
+            return emptyList();
+        }
+        return unmodifiableList(infopoints);
     }
 
     /**
      * @return the list of data references
      */
     public List<DataPatch> getDataReferences() {
-        return dataReferences;
+        if (dataReferences.isEmpty()) {
+            return emptyList();
+        }
+        return unmodifiableList(dataReferences);
     }
 
     /**
      * @return the list of exception handlers
      */
     public List<ExceptionHandler> getExceptionHandlers() {
-        return exceptionHandlers;
+        if (exceptionHandlers.isEmpty()) {
+            return emptyList();
+        }
+        return unmodifiableList(exceptionHandlers);
     }
 
     /**
      * @return the list of marks
      */
     public List<Mark> getMarks() {
-        return marks;
+        if (marks.isEmpty()) {
+            return emptyList();
+        }
+        return unmodifiableList(marks);
     }
 }