# HG changeset patch # User Artem Tikhomirov # Date 1313502347 -7200 # Node ID b61ed0f2c4da47f9b14dcf4a104a4a73d8ba18ae # Parent 5a6ab50b4cbf6ed3c939f3b7ca0368594a74227d Yet another slight perf/mem improvement for the tags per file sample diff -r 5a6ab50b4cbf -r b61ed0f2c4da test/org/tmatesoft/hg/test/MapTagsToFileRevisions.java --- a/test/org/tmatesoft/hg/test/MapTagsToFileRevisions.java Tue Aug 16 14:33:11 2011 +0200 +++ b/test/org/tmatesoft/hg/test/MapTagsToFileRevisions.java Tue Aug 16 15:45:47 2011 +0200 @@ -2,6 +2,7 @@ import java.io.File; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.LinkedList; import java.util.List; @@ -62,19 +63,26 @@ System.out.printf("Prepared tag revisions to analyze: %d ms\n", System.currentTimeMillis() - start); // repository.getManifest().walk(new HgManifest.Inspector() { - private final ArrayList tagIndexAtRev = new ArrayList(); + private int[] tagIndexAtRev = new int[4]; // it's unlikely there would be a lot of tags associated with a given cset private final Pool filenamePool = new Pool(); private final Pool nodeidPool = new Pool(); public boolean begin(int mainfestRevision, Nodeid nid, int changelogRevision) { Nodeid cset = clogrmap.revision(changelogRevision); - tagIndexAtRev.clear(); - for (int i = 0; i < allTags.length; i++) { + Arrays.fill(tagIndexAtRev, -1); + for (int i = 0, x = 0; i < allTags.length; i++) { if (cset.equals(allTags[i].revision())) { - tagIndexAtRev.add(i); + tagIndexAtRev[x++] = i; + if (x == tagIndexAtRev.length) { + // expand twice as much + int[] expanded = new int[x << 1]; + System.arraycopy(tagIndexAtRev, 0, expanded, 0, x); + expanded[x] = -1; // just in case there'd be no more tags associated with this cset + tagIndexAtRev = expanded; + } } } - if (tagIndexAtRev.isEmpty()) { + if (tagIndexAtRev[0] == -1) { System.out.println("Can't happen, provided we iterate over revisions with tags only"); } return true; @@ -88,6 +96,9 @@ file2rev2tag.put(fname, m = new Nodeid[allTags.length]); } for (int tagIndex : tagIndexAtRev) { + if (tagIndex == -1) { + break; + } if (m[tagIndex] != null) { System.out.printf("There's another revision (%s) associated with tag %s already while we try to associate %s\n", m[tagIndex].shortNotation(), allTags[tagIndex].name(), nid.shortNotation()); }