From 8bd255a35671aafed7ffa5f297d38c8747672e35 Mon Sep 17 00:00:00 2001 From: James Roseborough Date: Mon, 19 Apr 2010 21:39:17 +0000 Subject: [PATCH] Prevent rehash when value is replaced in table. --- src/core/org/luaj/vm2/LuaTable.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/core/org/luaj/vm2/LuaTable.java b/src/core/org/luaj/vm2/LuaTable.java index 12323684..081365b0 100644 --- a/src/core/org/luaj/vm2/LuaTable.java +++ b/src/core/org/luaj/vm2/LuaTable.java @@ -437,14 +437,17 @@ public class LuaTable extends LuaValue { if ( value.isnil() ) hashRemove(key); else { - if ( checkLoadFactor() ) - rehash(); - + if ( hashKeys.length == 0 ) { + hashKeys = new LuaValue[ MIN_HASH_CAPACITY ]; + hashValues = new LuaValue[ MIN_HASH_CAPACITY ]; + } int slot = hashFindSlot( key ); if ( hashFillSlot( slot, value ) ) return; hashKeys[slot] = key; hashValues[slot] = value; + if ( checkLoadFactor() ) + rehash(); } }