# HG changeset patch # User Doug Simon # Date 1366904744 -7200 # Node ID d73ad771a602ebafc800aa138d241cd59c86196c # Parent 90ee20fd2c058e6f98fb1d395dc5c72f8ce6f715 return immutable collections from (some) CompilationResult getters diff -r 90ee20fd2c05 -r d73ad771a602 graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CompilationResult.java --- 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 getInfopoints() { - return infopoints; + if (infopoints.isEmpty()) { + return emptyList(); + } + return unmodifiableList(infopoints); } /** * @return the list of data references */ public List getDataReferences() { - return dataReferences; + if (dataReferences.isEmpty()) { + return emptyList(); + } + return unmodifiableList(dataReferences); } /** * @return the list of exception handlers */ public List getExceptionHandlers() { - return exceptionHandlers; + if (exceptionHandlers.isEmpty()) { + return emptyList(); + } + return unmodifiableList(exceptionHandlers); } /** * @return the list of marks */ public List getMarks() { - return marks; + if (marks.isEmpty()) { + return emptyList(); + } + return unmodifiableList(marks); } }