From 5071885d10003c6c9711f9bc01b2ed737c3286ae Mon Sep 17 00:00:00 2001 From: TomyLobo Date: Tue, 22 Nov 2011 02:33:01 +0100 Subject: [PATCH] Expression parser: Extended the index range of the megabuf function and renamed it to gmegabuf --- .../expression/runtime/Functions.java | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) 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 f61efd53f..d5817764c 100644 --- a/src/main/java/com/sk89q/worldedit/expression/runtime/Functions.java +++ b/src/main/java/com/sk89q/worldedit/expression/runtime/Functions.java @@ -262,15 +262,25 @@ public final class Functions { } - private static final double[] megabuf = new double[1024]; + private static final Map gmegabuf = new HashMap(); - @Dynamic - public static final double megabuf(RValue index) throws EvaluationException { - return megabuf[(int) index.getValue()]; + private static double[] getSubBuffer(Integer key) { + double[] ret = gmegabuf.get(key); + if (ret == null) { + gmegabuf.put(key, ret = new double[1024]); + } + return ret; } @Dynamic - public static final double megabuf(RValue index, double value) throws EvaluationException { - return megabuf[(int) index.getValue()] = value; + public static final double gmegabuf(RValue index) throws EvaluationException { + final int intIndex = (int) index.getValue(); + return getSubBuffer(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; } }