From 613f3884d46eae21d60099a20781525af9b3c60e Mon Sep 17 00:00:00 2001 From: TomyLobo Date: Fri, 13 Jul 2012 12:24:14 +0200 Subject: [PATCH] Reorganized megabuf a bit. --- .../expression/runtime/Functions.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 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 51d82402c..0fae2347c 100644 --- a/src/main/java/com/sk89q/worldedit/expression/runtime/Functions.java +++ b/src/main/java/com/sk89q/worldedit/expression/runtime/Functions.java @@ -281,28 +281,32 @@ public final class Functions { return ret; } + private static double getBufferItem(final Map megabuf, final int index) { + return getSubBuffer(megabuf, index & ~1023)[index & 1023]; + } + + private static double setBufferItem(final Map megabuf, final int index, double value) { + return getSubBuffer(megabuf, index & ~1023)[index & 1023] = value; + } + @Dynamic public static final double gmegabuf(RValue index) throws EvaluationException { - final int intIndex = (int) index.getValue(); - return getSubBuffer(gmegabuf, intIndex & ~1023)[intIndex & 1023]; + return getBufferItem(gmegabuf, (int) index.getValue()); } @Dynamic public static final double gmegabuf(RValue index, double value) throws EvaluationException { - final int intIndex = (int) index.getValue(); - return getSubBuffer(gmegabuf, intIndex & ~1023)[intIndex & 1023] = value; + return setBufferItem(gmegabuf, (int) index.getValue(), 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]; + return getBufferItem(Expression.getInstance().getMegabuf(), (int) index.getValue()); } @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; + return setBufferItem(Expression.getInstance().getMegabuf(), (int) index.getValue(), value); }