Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Lazy allocation of HashMap for VMHash storage on JVM.
  • Loading branch information
donaldh committed Sep 24, 2013
1 parent 601b8e9 commit f7c396a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/vm/jvm/runtime/org/perl6/nqp/sixmodel/reprs/VMHash.java
Expand Up @@ -23,7 +23,7 @@ public SixModelObject type_object_for(ThreadContext tc, SixModelObject HOW) {
public SixModelObject allocate(ThreadContext tc, STable st) {
VMHashInstance obj = new VMHashInstance();
obj.st = st;
obj.storage = new HashMap<String, SixModelObject>();
obj.storage = VMHashInstance.EMPTY_MAP;
return obj;
}

Expand All @@ -34,7 +34,7 @@ public StorageSpec get_value_storage_spec(ThreadContext tc, STable st) {
public SixModelObject deserialize_stub(ThreadContext tc, STable st) {
VMHashInstance obj = new VMHashInstance();
obj.st = st;
obj.storage = new HashMap<String, SixModelObject>();
obj.storage = VMHashInstance.EMPTY_MAP;
return obj;
}

Expand Down
Expand Up @@ -6,13 +6,19 @@
import org.perl6.nqp.sixmodel.SixModelObject;

public class VMHashInstance extends SixModelObject {
public static final HashMap<String, SixModelObject> EMPTY_MAP =
new HashMap<String, SixModelObject>();

public HashMap<String, SixModelObject> storage;

public SixModelObject at_key_boxed(ThreadContext tc, String key) {
return storage.get(key);
}

public void bind_key_boxed(ThreadContext tc, String key, SixModelObject value) {
if (storage == VMHashInstance.EMPTY_MAP) {
storage = new HashMap<String, SixModelObject>();
}
storage.put(key, value);
}

Expand Down

0 comments on commit f7c396a

Please sign in to comment.