Mercurial Hosting > luan
changeset 425:0a2fb80907f9
minor LuanTable cleanup
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Fri, 01 May 2015 17:18:23 -0600 |
parents | 750a68eceb1d |
children | 23a93c118042 |
files | core/src/luan/LuanTable.java core/src/luan/modules/TableLuan.java |
diffstat | 2 files changed, 9 insertions(+), 36 deletions(-) [+] |
line wrap: on
line diff
diff -r 750a68eceb1d -r 0a2fb80907f9 core/src/luan/LuanTable.java --- a/core/src/luan/LuanTable.java Fri May 01 16:33:42 2015 -0600 +++ b/core/src/luan/LuanTable.java Fri May 01 17:18:23 2015 -0600 @@ -52,6 +52,14 @@ } } + public LuanTable(LuanTable tbl) { + if( tbl.map != null && !tbl.map.isEmpty() ) + this.map = new LinkedHashMap<Object,Object>(tbl.map); + if( tbl.length() > 0 ) + this.list = new ArrayList<Object>(tbl.list); + this.metatable = tbl.metatable; + } + @Override public LuanTable shallowClone() { return new LuanTable(); } @@ -82,37 +90,6 @@ return list!=null ? list : Collections.emptyList(); } - private Map<Object,Object> map() { - return map!=null ? map : Collections.emptyMap(); - } -/* - @Override public boolean isSet() { - if( list != null ) { - for( Object obj : list ) { - if( obj!=null && !obj.equals(Boolean.TRUE) ) - return false; - } - } - if( map != null ) { - for( Object obj : map.values() ) { - if( !obj.equals(Boolean.TRUE) ) - return false; - } - } - return true; - } - - @Override public Set<Object> asSet() { - if( list == null || list.isEmpty() ) - return map!=null ? map.keySet() : Collections.emptySet(); - Set<Object> rtn = map!=null ? new HashSet<Object>(map.keySet()) : new HashSet<Object>(); - for( int i=1; i<=list.size(); i++ ) { - rtn.add(i); - } - return rtn; - } -*/ - public Object get(Object key) { if( list != null ) { Integer iT = Luan.asInteger(key); @@ -329,10 +306,6 @@ return map; } - public LuanTable cloneTable() { - return isList() ? new LuanTable(new ArrayList<Object>(asList())) : new LuanTable(asMap()); - } - @Override public final String toString() { return "table: " + Integer.toHexString(hashCode()); }
diff -r 750a68eceb1d -r 0a2fb80907f9 core/src/luan/modules/TableLuan.java --- a/core/src/luan/modules/TableLuan.java Fri May 01 16:33:42 2015 -0600 +++ b/core/src/luan/modules/TableLuan.java Fri May 01 17:18:23 2015 -0600 @@ -112,7 +112,7 @@ } public static LuanTable clone(LuanTable tbl) { - return tbl.cloneTable(); + return new LuanTable(tbl); } public static LuanTable new_property_table() {