From 3a8cc9b7f9a127d4a5bc3a820a90bbcd58d59b16 Mon Sep 17 00:00:00 2001 From: stepan <stepan.sindelar@oracle.com> Date: Mon, 28 Aug 2017 18:45:40 +0200 Subject: [PATCH] Remove some usages of getDataWithoutCopy() --- .../r/library/fastrGrid/DisplayList.java | 2 +- .../r/library/fastrGrid/DoSetViewPort.java | 63 +++++++++---------- .../truffle/r/library/fastrGrid/GPar.java | 26 ++++---- .../r/library/fastrGrid/GridState.java | 3 +- .../r/library/fastrGrid/GridUtils.java | 10 ++- .../truffle/r/library/fastrGrid/LPretty.java | 2 +- .../truffle/r/library/fastrGrid/LRaster.java | 4 +- .../r/library/fastrGrid/LUnsetViewPort.java | 2 +- .../r/library/fastrGrid/TransformMatrix.java | 5 +- .../truffle/r/library/fastrGrid/ViewPort.java | 4 +- .../library/fastrGrid/ViewPortTransform.java | 2 +- .../library/fastrGrid/device/GridDevice.java | 3 +- .../r/library/fastrGrid/graphics/CPar.java | 14 ++--- .../r/nodes/builtin/base/GrepFunctions.java | 2 +- .../truffle/r/nodes/builtin/base/Order.java | 47 +++++++------- .../truffle/r/nodes/builtin/base/Parse.java | 16 +++-- .../truffle/r/nodes/builtin/base/Pretty.java | 2 +- .../truffle/r/nodes/builtin/base/Rank.java | 4 +- .../base/printer/ValuePrinterNode.java | 2 +- .../truffle/r/runtime/PrettyIntevals.java | 6 +- .../truffle/r/runtime/data/RListBase.java | 4 ++ 21 files changed, 117 insertions(+), 106 deletions(-) diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/DisplayList.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/DisplayList.java index 89834ac50a..14cd2fda77 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/DisplayList.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/DisplayList.java @@ -49,7 +49,7 @@ public class DisplayList { static void initDisplayList(GridState gridState) { RList list = createInitialDisplayList(); - list.setDataAt(list.getInternalStore(), 0, gridState.getViewPort()); + list.setDataAt(0, gridState.getViewPort()); gridState.setDisplayList(list); gridState.setDisplayListIndex(1); } diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/DoSetViewPort.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/DoSetViewPort.java index f2d1290c6e..87ac3095c6 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/DoSetViewPort.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/DoSetViewPort.java @@ -36,6 +36,7 @@ import com.oracle.truffle.r.runtime.data.RDoubleVector; import com.oracle.truffle.r.runtime.data.RList; import com.oracle.truffle.r.runtime.data.RNull; import com.oracle.truffle.r.runtime.data.model.RAbstractContainer; +import com.oracle.truffle.r.runtime.data.model.RAbstractDoubleVector; import com.oracle.truffle.r.runtime.data.model.RAbstractIntVector; import com.oracle.truffle.r.runtime.env.REnvironment; @@ -54,12 +55,11 @@ final class DoSetViewPort { @TruffleBoundary public static RList doSetViewPort(RList pushedViewPort, boolean hasParent, boolean pushing) { GridState gridState = GridContext.getContext().getGridState(); - Object[] pushedVPData = pushedViewPort.getDataWithoutCopying(); if (hasParent && pushing) { RList parent = gridState.getViewPort(); - pushedVPData[ViewPort.PVP_PARENT] = parent; + pushedViewPort.setDataAt(ViewPort.PVP_PARENT, parent); REnvironment children = GridUtils.asEnvironment(parent.getDataAt(ViewPort.PVP_CHILDREN)); - children.safePut(RRuntime.asString(pushedVPData[ViewPort.VP_NAME]), pushedViewPort); + children.safePut(RRuntime.asString(pushedViewPort.getDataAt(ViewPort.VP_NAME)), pushedViewPort); } GridDevice currentDevice = GridContext.getContext().getCurrentDevice(); @@ -70,9 +70,9 @@ final class DoSetViewPort { calcViewportTransform(pushedViewPort, parent, doNotRecalculateParent, currentDevice, gpar); // TODO: clipping - pushedVPData[ViewPort.PVP_CLIPRECT] = RDataFactory.createDoubleVector(new double[]{0, 0, 0, 0}, RDataFactory.COMPLETE_VECTOR); - pushedVPData[ViewPort.PVP_DEVWIDTHCM] = scalar(Unit.inchesToCm(currentDevice.getWidth())); - pushedVPData[ViewPort.PVP_DEVHEIGHTCM] = scalar(Unit.inchesToCm(currentDevice.getHeight())); + pushedViewPort.setDataAt(ViewPort.PVP_CLIPRECT, RDataFactory.createDoubleVector(new double[]{0, 0, 0, 0}, RDataFactory.COMPLETE_VECTOR)); + pushedViewPort.setDataAt(ViewPort.PVP_DEVWIDTHCM, scalar(Unit.inchesToCm(currentDevice.getWidth()))); + pushedViewPort.setDataAt(ViewPort.PVP_DEVHEIGHTCM, scalar(Unit.inchesToCm(currentDevice.getHeight()))); assert pushedViewPort.verify(); return pushedViewPort; @@ -108,17 +108,17 @@ final class DoSetViewPort { } else { assert parent instanceof RList : "inconsistent data: parent of a viewport must be a list"; RList parentVPList = (RList) parent; - Object[] parentData = parentVPList.getDataWithoutCopying(); if (!incremental) { - calcViewportTransform(parentVPList, parentData[ViewPort.PVP_PARENT], false, device, deviceTopLevelGpar); + calcViewportTransform(parentVPList, parentVPList.getDataAt(ViewPort.PVP_PARENT), false, device, deviceTopLevelGpar); } - parentSize = new Size(Unit.cmToInches(GridUtils.asDouble(parentData[ViewPort.PVP_WIDTHCM])), Unit.cmToInches(GridUtils.asDouble(parentData[ViewPort.PVP_HEIGHTCM]))); - parentTransform = fromFlat(GridUtils.asDoubleVector(parentData[ViewPort.PVP_TRANS]).materialize().getDataWithoutCopying()); + parentSize = new Size(Unit.cmToInches(GridUtils.asDouble(parentVPList.getDataAt(ViewPort.PVP_WIDTHCM))), + Unit.cmToInches(GridUtils.asDouble(parentVPList.getDataAt(ViewPort.PVP_HEIGHTCM)))); + parentTransform = fromFlat(GridUtils.asDoubleVector(parentVPList.getDataAt(ViewPort.PVP_TRANS))); parentContext = ViewPortContext.fromViewPort(parentVPList); - parentAngle = asDouble(parentData[ViewPort.PVP_ROTATION]); + parentAngle = asDouble(parentVPList.getDataAt(ViewPort.PVP_ROTATION)); drawingContext = GPar.create(asList(viewPort.getDataAt(ViewPort.PVP_PARENTGPAR))); - boolean noLayout = (isNull(viewPort.getDataAt(ViewPort.VP_VALIDLPOSROW)) && isNull(viewPort.getDataAt(ViewPort.VP_VALIDLPOSCOL))) || isNull(parentData[ViewPort.VP_LAYOUT]); + boolean noLayout = (isNull(viewPort.getDataAt(ViewPort.VP_VALIDLPOSROW)) && isNull(viewPort.getDataAt(ViewPort.VP_VALIDLPOSCOL))) || isNull(parentVPList.getDataAt(ViewPort.VP_LAYOUT)); if (noLayout) { vpl = ViewPortLocation.fromViewPort(viewPort); } else { @@ -160,11 +160,10 @@ final class DoSetViewPort { calcViewPortLayout(viewPort, new Size(width, height), vpCtx, device, GPar.create(asList(viewPort.getDataAt(ViewPort.PVP_GPAR)))); } - Object[] viewPortData = viewPort.getDataWithoutCopying(); - viewPortData[ViewPort.PVP_WIDTHCM] = scalar(Unit.inchesToCm(width)); - viewPortData[ViewPort.PVP_HEIGHTCM] = scalar(Unit.inchesToCm(height)); - viewPortData[ViewPort.PVP_ROTATION] = scalar(rotationAngle); - viewPortData[ViewPort.PVP_TRANS] = RDataFactory.createDoubleVector(flatten(transform), RDataFactory.COMPLETE_VECTOR, new int[]{3, 3}); + viewPort.setDataAt(ViewPort.PVP_WIDTHCM, scalar(Unit.inchesToCm(width))); + viewPort.setDataAt(ViewPort.PVP_HEIGHTCM, scalar(Unit.inchesToCm(height))); + viewPort.setDataAt(ViewPort.PVP_ROTATION, scalar(rotationAngle)); + viewPort.setDataAt(ViewPort.PVP_TRANS, RDataFactory.createDoubleVector(flatten(transform), RDataFactory.COMPLETE_VECTOR, new int[]{3, 3})); } private static void calcViewPortLayout(RList viewPort, Size size, ViewPortContext parentVPCtx, GridDevice device, GPar gpar) { @@ -178,12 +177,12 @@ final class DoSetViewPort { // For both dimensions we find out which units are other than "null" for those we can // immediately calculate the physical size in npcWidth/npcHeights. The reducedWidth/Height // gives us how much of width/height is left after we take up the space by physical units - Object[] layoutData = asList(viewPort.getDataAt(ViewPort.VP_LAYOUT)).getDataWithoutCopying(); - RAbstractContainer layoutWidths = asAbstractContainer(layoutData[ViewPort.LAYOUT_WIDTHS]); + RList layoutList = asList(viewPort.getDataAt(ViewPort.VP_LAYOUT)); + RAbstractContainer layoutWidths = asAbstractContainer(layoutList.getDataAt(ViewPort.LAYOUT_WIDTHS)); assert Unit.getLength(layoutWidths) == layoutSize.ncol : "inconsistent layout size with layout widths"; double reducedWidth = getReducedDimension(layoutWidths, npcWidths, relativeWidths, size.getWidth(), conversionCtx, true); - RAbstractContainer layoutHeights = asAbstractContainer(layoutData[ViewPort.LAYOUT_HEIGHTS]); + RAbstractContainer layoutHeights = asAbstractContainer(layoutList.getDataAt(ViewPort.LAYOUT_HEIGHTS)); assert Unit.getLength(layoutHeights) == layoutSize.nrow : "inconsistent layout size with layout height"; double reducedHeight = getReducedDimension(layoutHeights, npcHeights, relativeHeights, size.getHeight(), conversionCtx, false); @@ -192,7 +191,7 @@ final class DoSetViewPort { // Firstly allocate the respected widths/heights and calculate how much space remains RList layoutAsList = asList(viewPort.getDataAt(ViewPort.VP_LAYOUT)); int respect = RRuntime.asInteger(layoutAsList.getDataAt(ViewPort.LAYOUT_VRESPECT)); - int[] layoutRespectMat = ((RAbstractIntVector) layoutAsList.getDataAt(ViewPort.LAYOUT_MRESPECT)).materialize().getDataWithoutCopying(); + RAbstractIntVector layoutRespectMat = ((RAbstractIntVector) layoutAsList.getDataAt(ViewPort.LAYOUT_MRESPECT)); if ((reducedHeight > 0 || reducedWidth > 0) && respect > 0) { double sumRelWidth = sumRelativeDimension(layoutWidths, relativeWidths, parentVPCtx, device, gpar, true); double sumRelHeight = sumRelativeDimension(layoutHeights, relativeHeights, parentVPCtx, device, gpar, false); @@ -253,12 +252,12 @@ final class DoSetViewPort { allocateRelativeDim(layoutSize, layoutHeights, npcHeights, relativeHeights, reducedHeight, respect, layoutRespectMat, device, gpar, parentVPCtx, false); // Create the result - Object[] vpData = viewPort.getDataWithoutCopying(); - vpData[ViewPort.PVP_WIDTHS] = RDataFactory.createDoubleVector(npcWidths, RDataFactory.COMPLETE_VECTOR); - vpData[ViewPort.PVP_HEIGHTS] = RDataFactory.createDoubleVector(npcHeights, RDataFactory.COMPLETE_VECTOR); + viewPort.setDataAt(ViewPort.PVP_WIDTHS, RDataFactory.createDoubleVector(npcWidths, RDataFactory.COMPLETE_VECTOR)); + viewPort.setDataAt(ViewPort.PVP_HEIGHTS, RDataFactory.createDoubleVector(npcHeights, RDataFactory.COMPLETE_VECTOR)); } - private static void allocateRelativeDim(LayoutSize layoutSize, RAbstractContainer layoutItems, double[] npcItems, boolean[] relativeItems, double reducedDim, int respect, int[] layoutRespectMat, + private static void allocateRelativeDim(LayoutSize layoutSize, RAbstractContainer layoutItems, double[] npcItems, boolean[] relativeItems, double reducedDim, int respect, + RAbstractIntVector layoutRespectMat, GridDevice device, GPar gpar, ViewPortContext parentVPCtx, boolean isWidth) { assert relativeItems.length == npcItems.length; UnitConversionContext layoutModeCtx = new UnitConversionContext(new Size(0, 0), parentVPCtx, device, gpar, 1, 0); @@ -282,28 +281,28 @@ final class DoSetViewPort { } } - private static boolean rowColRespected(int respected, int rowOrCol, int[] layoutRespectMat, LayoutSize layoutSize, boolean isColumn) { + private static boolean rowColRespected(int respected, int rowOrCol, RAbstractIntVector layoutRespectMat, LayoutSize layoutSize, boolean isColumn) { return isColumn ? colRespected(respected, rowOrCol, layoutRespectMat, layoutSize) : rowRespected(respected, rowOrCol, layoutRespectMat, layoutSize); } - private static boolean rowRespected(int respected, int row, int[] layoutRespectMat, LayoutSize layoutSize) { + private static boolean rowRespected(int respected, int row, RAbstractIntVector layoutRespectMat, LayoutSize layoutSize) { if (respected == 1) { return true; } for (int i = 0; i < layoutSize.ncol; i++) { - if (layoutRespectMat[i * layoutSize.nrow + row] != 0) { + if (layoutRespectMat.getDataAt(i * layoutSize.nrow + row) != 0) { return true; } } return false; } - private static boolean colRespected(int respected, int col, int[] layoutRespectMat, LayoutSize layoutSize) { + private static boolean colRespected(int respected, int col, RAbstractIntVector layoutRespectMat, LayoutSize layoutSize) { if (respected == 1) { return true; } for (int i = 0; i < layoutSize.nrow; i++) { - if (layoutRespectMat[col * layoutSize.nrow + i] != 0) { + if (layoutRespectMat.getDataAt(col * layoutSize.nrow + i) != 0) { return true; } } @@ -344,8 +343,8 @@ final class DoSetViewPort { // positions replaced with nrow/ncol already. private static ViewPortLocation calcViewportLocationFromLayout(LayoutPos pos, RList parentVP, Size parentSize) { // unlike in GnuR, we maintain parent viewport widths/heights in inches like anything else - double[] widths = GridUtils.asDoubleVector(parentVP.getDataAt(ViewPort.PVP_WIDTHS)).materialize().getDataWithoutCopying(); - double[] heights = GridUtils.asDoubleVector(parentVP.getDataAt(ViewPort.PVP_HEIGHTS)).materialize().getDataWithoutCopying(); + RAbstractDoubleVector widths = GridUtils.asDoubleVector(parentVP.getDataAt(ViewPort.PVP_WIDTHS)); + RAbstractDoubleVector heights = GridUtils.asDoubleVector(parentVP.getDataAt(ViewPort.PVP_HEIGHTS)); double totalWidth = sum(widths, 0, pos.layoutSize.ncol); double totalHeight = sum(heights, 0, pos.layoutSize.nrow); double width = sum(widths, pos.colMin, pos.colMax - pos.colMin + 1); diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GPar.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GPar.java index adba03004c..cbffadad57 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GPar.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GPar.java @@ -168,37 +168,37 @@ public final class GPar { } private static final class GParDrawingContext implements DrawingContext { - private final Object[] data; + private final RList data; private final int index; private GParDrawingContext(RList list, int index) { - data = list.getDataWithoutCopying(); + data = list; this.index = index; } @Override public byte[] getLineType() { - return convertNamedValue(data[GP_LTY], LINE_STYLES.length - 1, "line type", GParDrawingContext::lineTypeFromName, num -> LINE_STYLES[num]); + return convertNamedValue(data.getDataAt(GP_LTY), LINE_STYLES.length - 1, "line type", GParDrawingContext::lineTypeFromName, num -> LINE_STYLES[num]); } @Override public double getLineWidth() { - return asDouble(data[GP_LWD], index) * asDouble(data[GP_LEX], index); + return asDouble(data.getDataAt(GP_LWD), index) * asDouble(data.getDataAt(GP_LEX), index); } @Override public GridLineJoin getLineJoin() { - return convertNamedValue(data[GP_LINEJOIN], GridLineJoin.LAST_VALUE, "line join", GParDrawingContext::lineJoinFromName, GridLineJoin::fromInt); + return convertNamedValue(data.getDataAt(GP_LINEJOIN), GridLineJoin.LAST_VALUE, "line join", GParDrawingContext::lineJoinFromName, GridLineJoin::fromInt); } @Override public GridLineEnd getLineEnd() { - return convertNamedValue(data[GP_LINEEND], GridLineEnd.LAST_VALUE, "line end", GParDrawingContext::lineEndFromName, GridLineEnd::fromInt); + return convertNamedValue(data.getDataAt(GP_LINEEND), GridLineEnd.LAST_VALUE, "line end", GParDrawingContext::lineEndFromName, GridLineEnd::fromInt); } @Override public double getLineMitre() { - double value = asDouble(data[GP_LINEMITRE], index); + double value = asDouble(data.getDataAt(GP_LINEMITRE), index); if (value < 1.) { throw RError.error(RError.NO_CALLER, Message.GENERIC, "Invalid line mitre."); } @@ -212,22 +212,22 @@ public final class GPar { @Override public double getFontSize() { - return asDouble(data[GP_FONTSIZE], index) * asDouble(data[GP_CEX], index); + return asDouble(data.getDataAt(GP_FONTSIZE), index) * asDouble(data.getDataAt(GP_CEX), index); } @Override public GridFontStyle getFontStyle() { - return GridFontStyle.fromInt(GridUtils.asInt(data[GP_FONT], index)); + return GridFontStyle.fromInt(GridUtils.asInt(data.getDataAt(GP_FONT), index)); } @Override public String getFontFamily() { - return GridUtils.asString(data[GP_FONTFAMILY], index); + return GridUtils.asString(data.getDataAt(GP_FONTFAMILY), index); } @Override public double getLineHeight() { - return asDouble(data[GP_LINEHEIGHT], index); + return asDouble(data.getDataAt(GP_LINEHEIGHT), index); } @Override @@ -264,9 +264,9 @@ public final class GPar { } private GridColor getGridColor(int listIndex) { - Object value = data[listIndex]; + Object value = data.getDataAt(listIndex); GridColor color = GridColorUtils.getColor(value, index); - double alpha = asDouble(data[GP_ALPHA], index); + double alpha = asDouble(data.getDataAt(GP_ALPHA), index); if (alpha != 1.) { int newAlpha = Math.min(255, (int) (alpha * ((color.getAlpha() / 255.0) * 255))); return new GridColor(color.getRed(), color.getGreen(), color.getBlue(), newAlpha); diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GridState.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GridState.java index 5579a90519..3150a167f0 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GridState.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GridState.java @@ -70,8 +70,7 @@ public final class GridState { } public void setDisplayListElement(Object element) { - Object[] data = devState.displayList.getDataWithoutCopying(); - data[devState.displayListIndex] = element; + devState.displayList.setDataAt(devState.displayListIndex, element); } public boolean isDisplayListOn() { diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GridUtils.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GridUtils.java index e88b9cf5a6..494d46df7e 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GridUtils.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GridUtils.java @@ -228,13 +228,17 @@ final class GridUtils { } static double sum(double[] values) { - return sum(values, 0, values.length); + double result = 0; + for (int i = 0; i < values.length; i++) { + result += values[i]; + } + return result; } - static double sum(double[] values, int from, int length) { + static double sum(RAbstractDoubleVector values, int from, int length) { double result = 0; for (int i = 0; i < length; i++) { - result += values[from + i]; + result += values.getDataAt(from + i); } return result; } diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/LPretty.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/LPretty.java index 2d447deb2c..0872604572 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/LPretty.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/LPretty.java @@ -50,7 +50,7 @@ public abstract class LPretty extends RExternalBuiltinNode.Arg1 { double[] ns = new double[]{min}; double[] nu = new double[]{max}; int[] ndiv = new int[]{5}; - double unit = PrettyIntevals.pretty(getErrorContext(), ns, nu, new int[]{5}, 1, 0.25, new double[]{.8, 1.7}, 2, false); + double unit = PrettyIntevals.pretty(getErrorContext(), ns, nu, new int[]{5}, 1, 0.25, .8, 1.7, 2, false); if (nu[0] >= ns[0] + 1) { if (ns[0] * unit < min - 1e-7 * unit) { diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/LRaster.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/LRaster.java index 2b9c075642..4773b94e0c 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/LRaster.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/LRaster.java @@ -25,6 +25,7 @@ import com.oracle.truffle.r.nodes.builtin.RExternalBuiltinNode; import com.oracle.truffle.r.runtime.RError.Message; import com.oracle.truffle.r.runtime.RInternalError; import com.oracle.truffle.r.runtime.RRuntime; +import com.oracle.truffle.r.runtime.data.RIntVector; import com.oracle.truffle.r.runtime.data.RList; import com.oracle.truffle.r.runtime.data.RNull; import com.oracle.truffle.r.runtime.data.RStringVector; @@ -75,7 +76,8 @@ public abstract class LRaster extends RExternalBuiltinNode.Arg8 { int[] pixels; if (raster instanceof RAbstractIntVector && isNativeRaster(raster)) { - pixels = ((RAbstractIntVector) raster).materialize().getDataWithoutCopying(); + RIntVector rasterVec = ((RAbstractIntVector) raster).materialize(); + pixels = rasterVec.getDataTemp(); } else { int rasterLen = raster.getLength(); pixels = new int[rasterLen]; diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/LUnsetViewPort.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/LUnsetViewPort.java index 5ff2d5c8a5..25124315ba 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/LUnsetViewPort.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/LUnsetViewPort.java @@ -74,7 +74,7 @@ public abstract class LUnsetViewPort extends RExternalBuiltinNode.Arg1 { gridState.setViewPort(newVp); // remove the parent link from the old viewport - gvp.setDataAt(gvp.getInternalStore(), ViewPort.PVP_PARENT, RNull.instance); + gvp.setDataAt(ViewPort.PVP_PARENT, RNull.instance); return RNull.instance; } diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/TransformMatrix.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/TransformMatrix.java index 28ed32b803..ae64fd26f0 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/TransformMatrix.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/TransformMatrix.java @@ -15,6 +15,7 @@ import static com.oracle.truffle.r.runtime.nmath.MathConstants.M_PI; import com.oracle.truffle.r.runtime.RError; import com.oracle.truffle.r.runtime.RError.Message; +import com.oracle.truffle.r.runtime.data.model.RAbstractDoubleVector; // transcribed from matrix.c @@ -111,11 +112,11 @@ final class TransformMatrix { /** * Reverse operation to {@link #flatten(double[][])}. */ - static double[][] fromFlat(double[] flat) { + static double[][] fromFlat(RAbstractDoubleVector flat) { double[][] res = new double[3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - res[i][j] = flat[i + j * 3]; + res[i][j] = flat.getDataAt(i + j * 3); } } return res; diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/ViewPort.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/ViewPort.java index 6bd2592e16..813782bb25 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/ViewPort.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/ViewPort.java @@ -89,12 +89,12 @@ final class ViewPort { double devWidthCm = inchesToCm(device.getWidth()); boolean result = false; if (Math.abs(devWidthCm - asDouble(viewPort.getDataAt(PVP_DEVWIDTHCM))) >= 1e-6) { - viewPort.setDataAt(viewPort.getInternalStore(), PVP_DEVWIDTHCM, devWidthCm); + viewPort.setDataAt(PVP_DEVWIDTHCM, devWidthCm); result = true; } double devHeightCm = inchesToCm(device.getHeight()); if (Math.abs(devHeightCm - asDouble(viewPort.getDataAt(PVP_DEVHEIGHTCM))) >= 1e-6) { - viewPort.setDataAt(viewPort.getInternalStore(), PVP_DEVHEIGHTCM, devHeightCm); + viewPort.setDataAt(PVP_DEVHEIGHTCM, devHeightCm); } return result; } diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/ViewPortTransform.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/ViewPortTransform.java index 179ec60d18..db897108d6 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/ViewPortTransform.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/ViewPortTransform.java @@ -42,7 +42,7 @@ public final class ViewPortTransform { double height = Unit.cmToInches(GridUtils.asDouble(viewPort.getDataAt(ViewPort.PVP_HEIGHTCM))); double rotationAngle = GridUtils.asDouble(viewPort.getDataAt(ViewPort.VP_ANGLE)); RAbstractDoubleVector trans = GridUtils.asDoubleVector(viewPort.getDataAt(ViewPort.PVP_TRANS)); - double[][] transform = TransformMatrix.fromFlat(trans.materialize().getDataWithoutCopying()); + double[][] transform = TransformMatrix.fromFlat(trans); return new ViewPortTransform(width, height, rotationAngle, transform); } } diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/device/GridDevice.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/device/GridDevice.java index 87ed10b88a..d8ba61ad93 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/device/GridDevice.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/device/GridDevice.java @@ -97,7 +97,8 @@ public interface GridDevice { /** * Draws a raster image at specified position. The pixels array shall be treated as by row * matrix, the values are values compatible with the internal {@link GridColor} representation, - * e.g. what {@link GridColor#getRawValue()} would return. + * e.g. what {@link GridColor#getRawValue()} would return. The method is not required to make a + * defensive copy. */ void drawRaster(double leftX, double bottomY, double width, double height, int[] pixels, int pixelsColumnsCount, ImageInterpolation interpolation); diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/graphics/CPar.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/graphics/CPar.java index 524eeb912a..2f19eafd4d 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/graphics/CPar.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/graphics/CPar.java @@ -47,19 +47,19 @@ public final class CPar extends RExternalBuiltinNode { } GridDevice device = GridContext.getContext().getCurrentDevice(); - Object[] names = args.getArguments(); + RList names = RDataFactory.createList(args.getArguments()); // unwrap list if it is the first argument - if (names.length == 1) { + if (names.getLength() == 1) { Object first = args.getArgument(0); if (first instanceof RList) { - names = ((RList) first).getDataWithoutCopying(); + names = (RList) first; } } - Object[] result = new Object[names.length]; - String[] resultNames = new String[names.length]; - for (int i = 0; i < names.length; i++) { - resultNames[i] = RRuntime.asString(names[i]); + Object[] result = new Object[names.getLength()]; + String[] resultNames = new String[names.getLength()]; + for (int i = 0; i < names.getLength(); i++) { + resultNames[i] = RRuntime.asString(names.getDataAt(i)); result[i] = getParam(resultNames[i], device); } return RDataFactory.createList(result, RDataFactory.createStringVector(resultNames, RDataFactory.COMPLETE_VECTOR)); diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/GrepFunctions.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/GrepFunctions.java index 177902b34d..2be3b641a8 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/GrepFunctions.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/GrepFunctions.java @@ -1105,7 +1105,7 @@ public class GrepFunctions { String txt = vector.getDataAt(i); res = RDataFactory.createIntVector(txt.length()); for (int j = 0; j < txt.length(); j++) { - res.setDataAt(res.getDataWithoutCopying(), j, j + 1); + res.setDataAt(res.getInternalStore(), j, j + 1); } setMatchLengthAttrNode.execute(res, RDataFactory.createIntVector(txt.length())); if (useBytes) { diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Order.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Order.java index 3bfa03b888..36df142643 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Order.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Order.java @@ -85,9 +85,8 @@ public abstract class Order extends RPrecedenceBuiltinNode { int n = v.getLength(); reportWork(n); - RIntVector indxVec = RDataFactory.createIntVector(createIndexes(v, n, naLast), RDataFactory.COMPLETE_VECTOR); - initOrderVector1(needsStringCollation).execute(indxVec, v, naLast, dec, null); - int[] indx = indxVec.getDataWithoutCopying(); + int[] indx = createIndexes(v, n, naLast); + initOrderVector1(needsStringCollation).execute(indx, v, naLast, dec, null); for (int i = 0; i < indx.length; i++) { indx[i] = indx[i] + 1; } @@ -321,14 +320,13 @@ public abstract class Order extends RPrecedenceBuiltinNode { this.needsStringCollation = needsStringCollation; } - public abstract Object execute(Object v, Object dv, byte naLast, boolean dec, Object rho); + public abstract Object execute(int[] v, Object dv, byte naLast, boolean dec, Object rho); @Specialization - protected Object orderVector1(RIntVector indxVec, RAbstractIntVector dv, byte naLast, boolean decreasing, Object rho) { - if (indxVec.getLength() < 2) { - return indxVec; + protected Object orderVector1(int[] indx, RAbstractIntVector dv, byte naLast, boolean decreasing, Object rho) { + if (indx.length < 2) { + return indx; } - int[] indx = indxVec.getDataWithoutCopying(); int lo = 0; int hi = indx.length - 1; if (rho == null) { @@ -359,15 +357,14 @@ public abstract class Order extends RPrecedenceBuiltinNode { } sort(indx, dv, lo, hi, decreasing); - return indxVec; + return indx; } @Specialization - protected Object orderVector1(RIntVector indxVec, RAbstractDoubleVector dv, byte naLast, boolean decreasing, Object rho) { - if (indxVec.getLength() < 2) { - return indxVec; + protected Object orderVector1(int[] indx, RAbstractDoubleVector dv, byte naLast, boolean decreasing, Object rho) { + if (indx.length < 2) { + return indx; } - int[] indx = indxVec.getDataWithoutCopying(); int lo = 0; int hi = indx.length - 1; if (rho == null && !RRuntime.isNA(naLast)) { @@ -396,15 +393,14 @@ public abstract class Order extends RPrecedenceBuiltinNode { } sort(indx, dv, lo, hi, decreasing); - return indxVec; + return indx; } @Specialization - protected Object orderVector1(RIntVector indxVec, RAbstractStringVector dv, byte naLast, boolean decreasing, Object rho) { - if (indxVec.getLength() < 2) { - return indxVec; + protected Object orderVector1(int[] indx, RAbstractStringVector dv, byte naLast, boolean decreasing, Object rho) { + if (indx.length < 2) { + return indx; } - int[] indx = indxVec.getDataWithoutCopying(); int lo = 0; int hi = indx.length - 1; if (rho == null) { @@ -435,15 +431,14 @@ public abstract class Order extends RPrecedenceBuiltinNode { } sort(indx, dv, lo, hi, decreasing); - return indxVec; + return indx; } @Specialization - protected Object orderVector1(RIntVector indxVec, RAbstractComplexVector dv, byte naLast, boolean decreasing, Object rho) { - if (indxVec.getLength() < 2) { - return indxVec; + protected Object orderVector1(int[] indx, RAbstractComplexVector dv, byte naLast, boolean decreasing, Object rho) { + if (indx.length < 2) { + return indx; } - int[] indx = indxVec.getDataWithoutCopying(); int lo = 0; int hi = indx.length - 1; if (rho == null) { @@ -474,14 +469,14 @@ public abstract class Order extends RPrecedenceBuiltinNode { } sort(indx, dv, lo, hi, decreasing); - return indxVec; + return indx; } @SuppressWarnings("unused") @Specialization - protected Object orderVector1(RIntVector indxVec, RList dv, byte naLast, boolean decreasing, Object rho) { + protected Object orderVector1(int[] indx, RList dv, byte naLast, boolean decreasing, Object rho) { /* Only needed to satisfy .Internal(rank) in unit test */ - return indxVec; + return indx; } private void sort(int[] indx, RAbstractDoubleVector dv, int lo, int hi, boolean dec) { diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Parse.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Parse.java index 5d38f5473f..30de7c5d7d 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Parse.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Parse.java @@ -123,18 +123,17 @@ public abstract class Parse extends RBuiltinNode.Arg6 { } catch (IOException ex) { throw error(RError.Message.PARSE_ERROR); } - return doParse(connection, n, lines, prompt, srcFile, encoding); + return doParse(connection, n, coalesce(lines), prompt, srcFile, encoding); } @TruffleBoundary @Specialization protected RExpression parse(int conn, int n, RAbstractStringVector text, String prompt, Object srcFile, String encoding) { RConnection connection = RConnection.fromIndex(conn); - return doParse(connection, n, text.materialize().getDataWithoutCopying(), prompt, srcFile, encoding); + return doParse(connection, n, coalesce(text), prompt, srcFile, encoding); } - private RExpression doParse(RConnection conn, int n, String[] lines, @SuppressWarnings("unused") String prompt, Object srcFile, @SuppressWarnings("unused") String encoding) { - String coalescedLines = coalesce(lines); + private RExpression doParse(RConnection conn, int n, String coalescedLines, @SuppressWarnings("unused") String prompt, Object srcFile, @SuppressWarnings("unused") String encoding) { if (coalescedLines.length() == 0 || n == 0) { return RDataFactory.createExpression(new Object[0]); } @@ -158,6 +157,15 @@ public abstract class Parse extends RBuiltinNode.Arg6 { } } + private static String coalesce(RAbstractStringVector lines) { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < lines.getLength(); i++) { + sb.append(lines.getDataAt(i)); + sb.append('\n'); + } + return sb.toString(); + } + private static String coalesce(String[] lines) { StringBuilder sb = new StringBuilder(); for (String line : lines) { diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Pretty.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Pretty.java index f44ff63f51..64f2c9f744 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Pretty.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Pretty.java @@ -63,7 +63,7 @@ public abstract class Pretty extends RBuiltinNode.Arg7 { double[] lo = new double[]{l}; double[] up = new double[]{u}; int[] ndiv = new int[]{n}; - PrettyIntevals.pretty(getErrorContext(), lo, up, ndiv, minN, shrinkSml, hi.materialize().getDataWithoutCopying(), epsCorrect, true); + PrettyIntevals.pretty(getErrorContext(), lo, up, ndiv, minN, shrinkSml, hi.getDataAt(0), hi.getDataAt(1), epsCorrect, true); Object[] data = new Object[3]; data[0] = lo[0]; data[1] = up[0]; diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Rank.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Rank.java index c15016ffb9..d9c48f7c88 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Rank.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Rank.java @@ -42,7 +42,6 @@ import com.oracle.truffle.r.runtime.RRuntime; import com.oracle.truffle.r.runtime.RType; import com.oracle.truffle.r.runtime.builtins.RBuiltin; import com.oracle.truffle.r.runtime.data.RDataFactory; -import com.oracle.truffle.r.runtime.data.RIntVector; import com.oracle.truffle.r.runtime.data.model.RAbstractLogicalVector; import com.oracle.truffle.r.runtime.data.model.RAbstractVector; @@ -112,9 +111,8 @@ public abstract class Rank extends RBuiltinNode.Arg3 { for (int i = 0; i < n; i++) { indx[i] = i; } - RIntVector indxVec = RDataFactory.createIntVector(indx, RDataFactory.COMPLETE_VECTOR); RAbstractVector x = xa instanceof RAbstractLogicalVector ? xa.castSafe(RType.Integer, isNAProfile) : xa; - initOrderVector1().execute(indxVec, x, RRuntime.LOGICAL_TRUE, false, rho); + initOrderVector1().execute(indx, x, RRuntime.LOGICAL_TRUE, false, rho); initOrderCmp(); int j; for (int i = 0; i < n; i = j + 1) { diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/printer/ValuePrinterNode.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/printer/ValuePrinterNode.java index ca3ba2e74e..bea08a0ce8 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/printer/ValuePrinterNode.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/printer/ValuePrinterNode.java @@ -289,7 +289,7 @@ public final class ValuePrinterNode extends RBaseNode { RAbstractStringVector abstractNames = new RStringWrapper(size, keys); RStringVector names = RDataFactory.createStringVector(size); for (int i = 0; i < size; i++) { - names.getDataWithoutCopying()[i] = abstractNames.getDataAt(i); + names.setDataAt(names.getInternalStore(), i, abstractNames.getDataAt(i)); } class RListWrapper extends TruffleObjectWrapper implements RAbstractListVector { diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/PrettyIntevals.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/PrettyIntevals.java index 9ff10b704e..f7fa137234 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/PrettyIntevals.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/PrettyIntevals.java @@ -25,7 +25,7 @@ public final class PrettyIntevals { // transcribed from pretty.c public static double pretty(RBaseNode errorCtx, double[] lo, double[] up, int[] ndiv, int minN, - double shrinkSml, double[] highUFact, + double shrinkSml, double highUFact0, double highUFact1, int epsCorrection, boolean returnBounds) { /* * From version 0.65 on, we had rounding_eps := 1e-5, before, r..eps = 0 1e-7 is consistent @@ -33,8 +33,8 @@ public final class PrettyIntevals { */ double roundingEps = 1e-7; - double h = highUFact[0]; - double h5 = highUFact[1]; + double h = highUFact0; + double h5 = highUFact1; double dx; double cell; diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RListBase.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RListBase.java index abd4bf2d47..4a796edb84 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RListBase.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RListBase.java @@ -77,6 +77,10 @@ public abstract class RListBase extends RVector<Object[]> implements RAbstractLi return ((Object[]) store)[index]; } + public void setDataAt(int index, Object value) { + setDataAt(data, index, value); + } + @Override public void setDataAt(Object store, int index, Object valueArg) { assert valueArg != null : "lists must not contain nulls"; -- GitLab