From 9cdac001e371d8c35a3150faf6c180602afb5edf Mon Sep 17 00:00:00 2001 From: TomyLobo Date: Wed, 30 Nov 2011 05:27:11 +0100 Subject: [PATCH] Added a megabuf function to the expression parser, which works like gmegabuf, except that there is one buffer per Expression instance. --- .../worldedit/expression/Expression.java | 5 ++++ .../expression/runtime/Functions.java | 23 +++++++++++++++---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/expression/Expression.java b/src/main/java/com/sk89q/worldedit/expression/Expression.java index 7d5ffa55f..7b981de7d 100644 --- a/src/main/java/com/sk89q/worldedit/expression/Expression.java +++ b/src/main/java/com/sk89q/worldedit/expression/Expression.java @@ -63,6 +63,7 @@ public class Expression { private final Map variables = new HashMap(); private final String[] variableNames; private RValue root; + private final Map megabuf = new HashMap(); public static Expression compile(String expression, String... variableNames) throws ExpressionException { return new Expression(expression, variableNames); @@ -151,4 +152,8 @@ public class Expression { instance.set(null); } } + + public Map getMegabuf() { + return megabuf; + } } diff --git a/src/main/java/com/sk89q/worldedit/expression/runtime/Functions.java b/src/main/java/com/sk89q/worldedit/expression/runtime/Functions.java index 4bb811a13..9fe68ac9f 100644 --- a/src/main/java/com/sk89q/worldedit/expression/runtime/Functions.java +++ b/src/main/java/com/sk89q/worldedit/expression/runtime/Functions.java @@ -26,6 +26,7 @@ import java.util.List; import java.util.Map; import java.util.Random; +import com.sk89q.worldedit.expression.Expression; import com.sk89q.worldedit.expression.runtime.Function.Dynamic; /** @@ -272,10 +273,10 @@ public final class Functions { private static final Map gmegabuf = new HashMap(); - private static double[] getSubBuffer(Integer key) { - double[] ret = gmegabuf.get(key); + private static double[] getSubBuffer(Map megabuf, Integer key) { + double[] ret = megabuf.get(key); if (ret == null) { - gmegabuf.put(key, ret = new double[1024]); + megabuf.put(key, ret = new double[1024]); } return ret; } @@ -283,13 +284,25 @@ public final class Functions { @Dynamic public static final double gmegabuf(RValue index) throws EvaluationException { final int intIndex = (int) index.getValue(); - return getSubBuffer(intIndex & ~1023)[intIndex & 1023]; + return getSubBuffer(gmegabuf, intIndex & ~1023)[intIndex & 1023]; } @Dynamic public static final double gmegabuf(RValue index, double value) throws EvaluationException { final int intIndex = (int) index.getValue(); - return getSubBuffer(intIndex & ~1023)[intIndex & 1023] = value; + return getSubBuffer(gmegabuf, intIndex & ~1023)[intIndex & 1023] = value; + } + + @Dynamic + public static final double megabuf(RValue index) throws EvaluationException { + final int intIndex = (int) index.getValue(); + return getSubBuffer(Expression.getInstance().getMegabuf(), intIndex & ~1023)[intIndex & 1023]; + } + + @Dynamic + public static final double megabuf(RValue index, double value) throws EvaluationException { + final int intIndex = (int) index.getValue(); + return getSubBuffer(Expression.getInstance().getMegabuf(), intIndex & ~1023)[intIndex & 1023] = value; }