From 5288419628b61e24075cd65a29f636b55eccc6e2 Mon Sep 17 00:00:00 2001 From: Haiyang Date: Fri, 18 Jan 2019 13:09:50 +0100 Subject: [PATCH] make the iidToLocation string cache on-demand to save memory --- .../ch/usi/inf/nodeprof/utils/SourceMapping.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/ch.usi.inf.nodeprof/src/ch/usi/inf/nodeprof/utils/SourceMapping.java b/src/ch.usi.inf.nodeprof/src/ch/usi/inf/nodeprof/utils/SourceMapping.java index 9057c481..ced54cb0 100644 --- a/src/ch.usi.inf.nodeprof/src/ch/usi/inf/nodeprof/utils/SourceMapping.java +++ b/src/ch.usi.inf.nodeprof/src/ch/usi/inf/nodeprof/utils/SourceMapping.java @@ -55,9 +55,6 @@ public static int getIIDForSourceSection(SourceSection sourceSection) { } int newIId = ++iidGen; assert (newIId < Integer.MAX_VALUE); - StringBuilder b = makeLocationString(sourceSection); - - iidMap.put(newIId, b.toString()); sourceSet.put(sourceSection, newIId); idToSource.put(newIId, sourceSection); return newIId; @@ -65,7 +62,15 @@ public static int getIIDForSourceSection(SourceSection sourceSection) { @TruffleBoundary public static String getLocationForIID(int iid) { - return iidMap.get(iid); + if (iidMap.containsKey(iid)) { + return iidMap.get(iid); + } else if (idToSource.containsKey(iid)) { + String res = makeLocationString(idToSource.get(iid)).toString(); + iidMap.put(iid, res); + return res; + } else { + return null; + } } @TruffleBoundary