Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Avoid allocating HashMaps when lexical vars are null.
  • Loading branch information
donaldh committed Oct 4, 2013
1 parent 5cab6ef commit 464b5d4
Showing 1 changed file with 32 additions and 20 deletions.
52 changes: 32 additions & 20 deletions src/vm/jvm/runtime/org/perl6/nqp/runtime/StaticCodeInfo.java
Expand Up @@ -86,47 +86,59 @@ public class StaticCodeInfo implements Cloneable {
public boolean hasExitHandler;

public Integer oTryGetLexicalIdx(String name) {
if (oLexicalMap == null) {
HashMap<String, Integer> map = new HashMap<String, Integer>();
if (oLexicalNames != null)
if (oLexicalNames != null) {
if (oLexicalMap == null) {
HashMap<String, Integer> map = new HashMap<String, Integer>(oLexicalNames.length);
for (int i = 0; i < oLexicalNames.length; i++)
map.put(oLexicalNames[i], i);
oLexicalMap = map;
oLexicalMap = map;
}
return oLexicalMap.get(name);
} else {
return null;
}
return oLexicalMap.get(name);
}

public Integer iTryGetLexicalIdx(String name) {
if (iLexicalMap == null) {
HashMap<String, Integer> map = new HashMap<String, Integer>();
if (iLexicalNames != null)
if (iLexicalNames != null) {
if (iLexicalMap == null) {
HashMap<String, Integer> map = new HashMap<String, Integer>(iLexicalNames.length);
for (int i = 0; i < iLexicalNames.length; i++)
map.put(iLexicalNames[i], i);
iLexicalMap = map;
iLexicalMap = map;
}
return iLexicalMap.get(name);
} else {
return null;
}
return iLexicalMap.get(name);
}

public Integer nTryGetLexicalIdx(String name) {
if (nLexicalMap == null) {
HashMap<String, Integer> map = new HashMap<String, Integer>();
if (nLexicalNames != null)
if (nLexicalNames != null) {
if (nLexicalMap == null) {
HashMap<String, Integer> map = new HashMap<String, Integer>(nLexicalNames.length);
for (int i = 0; i < nLexicalNames.length; i++)
map.put(nLexicalNames[i], i);
nLexicalMap = map;
nLexicalMap = map;
}
return nLexicalMap.get(name);
} else {
return null;
}
return nLexicalMap.get(name);
}

public Integer sTryGetLexicalIdx(String name) {
if (sLexicalMap == null) {
HashMap<String, Integer> map = new HashMap<String, Integer>();
if (sLexicalNames != null)
if (sLexicalNames != null) {
if (sLexicalMap == null) {
HashMap<String, Integer> map = new HashMap<String, Integer>(sLexicalNames.length);
for (int i = 0; i < sLexicalNames.length; i++)
map.put(sLexicalNames[i], i);
sLexicalMap = map;
sLexicalMap = map;
}
return sLexicalMap.get(name);
} else {
return null;
}
return sLexicalMap.get(name);
}

/**
Expand Down

0 comments on commit 464b5d4

Please sign in to comment.