Skip to content

Commit

Permalink
cache place indexes, it is important for large models.
Browse files Browse the repository at this point in the history
  • Loading branch information
yanntm committed May 4, 2024
1 parent 4275422 commit 143f7e0
Showing 1 changed file with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,26 @@ public void endElement(String uri, String localName, String baliseName)
}
}

private Map<String, Integer> pcache = null;

private int findPlace(String name) {
int index = spec.getPlaceIndex(normalizeName(name));
if (index < 0) {
System.out.println("Unknown place :\""+name+"\" in property !");
throw new IllegalArgumentException("Unknown place :\""+name+"\" in property !");
}
return index;
if (spec instanceof ISparsePetriNet) {
ISparsePetriNet spn = (ISparsePetriNet) spec;
if (pcache == null) {
// Initialize the cache with an appropriate initial capacity to optimize performance and minimize rehashing
pcache = new HashMap<>((spn.getPnames().size() * 4 + 2) / 3);
int i = 0;
for (String pl : spn.getPnames()) {
pcache.put(pl, i++);
}
}
}
Integer index = (pcache == null) ? spec.getPlaceIndex(normalizeName(name)) : pcache.get(normalizeName(name));
if (index == null || index < 0) {
System.out.println("Unknown place :\"" + name + "\" in property !");
throw new IllegalArgumentException("Unknown place :\"" + name + "\" in property !");
}
return index;
}

public void popNary(Op op) {
Expand Down

0 comments on commit 143f7e0

Please sign in to comment.