Mercurial > hg4j
diff src/org/tmatesoft/hg/internal/RevlogStream.java @ 288:b11f6a08f748
Avoid boxing int values and list resizes on revlog read
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Sat, 10 Sep 2011 00:18:39 +0200 |
parents | 35125450c804 |
children | 981f9f50bb6c |
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/internal/RevlogStream.java Wed Sep 07 09:33:27 2011 +0200 +++ b/src/org/tmatesoft/hg/internal/RevlogStream.java Sat Sep 10 00:18:39 2011 +0200 @@ -269,8 +269,6 @@ if (baseRevisions != null && baseRevisions.length > 0) { return; } - ArrayList<Integer> resBases = new ArrayList<Integer>(); - ArrayList<Integer> resOffsets = new ArrayList<Integer>(); DataAccess da = getIndexStream(); try { if (da.isEmpty()) { @@ -282,6 +280,14 @@ da.readInt(); // just to skip next 4 bytes of offset + flags final int INLINEDATA = 1 << 16; inline = (versionField & INLINEDATA) != 0; + IntVector resBases, resOffsets = null; + int entryCountGuess = da.length() / REVLOGV1_RECORD_SIZE; + if (inline) { + entryCountGuess >>>= 2; // pure guess, assume useful data takes 3/4 of total space + resOffsets = new IntVector(entryCountGuess, 5000); + } + resBases = new IntVector(entryCountGuess, 5000); + long offset = 0; // first offset is always 0, thus Hg uses it for other purposes while(true) { int compressedLen = da.readInt(); @@ -309,9 +315,9 @@ } if (da.isEmpty()) { // fine, done then - baseRevisions = toArray(resBases); + baseRevisions = resBases.toArray(true); if (inline) { - indexRecordOffset = toArray(resOffsets); + indexRecordOffset = resOffsets.toArray(true); } break; } else {