Improve weak table implementation

This commit is contained in:
James Roseborough
2010-07-06 05:26:19 +00:00
parent dceadf2f82
commit e744b9be2b
3 changed files with 4 additions and 4 deletions

View File

@@ -30,7 +30,7 @@ public class LuaTable extends LuaValue {
protected LuaValue[] array; protected LuaValue[] array;
protected LuaValue[] hashKeys; protected LuaValue[] hashKeys;
protected LuaValue[] hashValues; protected LuaValue[] hashValues;
private int hashEntries; protected int hashEntries;
protected LuaValue m_metatable; protected LuaValue m_metatable;
public LuaTable() { public LuaTable() {
@@ -170,7 +170,7 @@ public class LuaTable extends LuaValue {
return hashget( key ); return hashget( key );
} }
private LuaValue hashget(LuaValue key) { protected LuaValue hashget(LuaValue key) {
if ( hashEntries > 0 ) { if ( hashEntries > 0 ) {
LuaValue v = hashValues[hashFindSlot(key)]; LuaValue v = hashValues[hashFindSlot(key)];
return v!=null? v: NIL; return v!=null? v: NIL;

View File

@@ -317,8 +317,9 @@ public class LuaValue extends Varargs {
// lua number/string conversion // lua number/string conversion
public LuaString strvalue() { typerror("strValue"); return null; } public LuaString strvalue() { typerror("strValue"); return null; }
public LuaValue strongkey() { return this; } public LuaValue strongkey() { return strongvalue(); }
public LuaValue strongvalue() { return this; } public LuaValue strongvalue() { return this; }
public boolean isweaknil() { return false; }
// conversion from java values // conversion from java values
public static LuaBoolean valueOf(boolean b) { return b? LuaValue.TRUE: FALSE; }; public static LuaBoolean valueOf(boolean b) { return b? LuaValue.TRUE: FALSE; };

View File

@@ -269,7 +269,6 @@ public class WeakTable extends LuaTable {
this.weakvalue = weakvalue; this.weakvalue = weakvalue;
} }
// when looking up the value, look in the keys metatable
public LuaValue strongvalue() { public LuaValue strongvalue() {
LuaValue key = weakkey.strongkey(); LuaValue key = weakkey.strongkey();
if ( key.isnil() ) if ( key.isnil() )