Mercurial > jhg
comparison 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 |
comparison
equal
deleted
inserted
replaced
287:ed6b74a58c66 | 288:b11f6a08f748 |
---|---|
267 | 267 |
268 private void initOutline() { | 268 private void initOutline() { |
269 if (baseRevisions != null && baseRevisions.length > 0) { | 269 if (baseRevisions != null && baseRevisions.length > 0) { |
270 return; | 270 return; |
271 } | 271 } |
272 ArrayList<Integer> resBases = new ArrayList<Integer>(); | |
273 ArrayList<Integer> resOffsets = new ArrayList<Integer>(); | |
274 DataAccess da = getIndexStream(); | 272 DataAccess da = getIndexStream(); |
275 try { | 273 try { |
276 if (da.isEmpty()) { | 274 if (da.isEmpty()) { |
277 // do not fail with exception if stream is empty, it's likely intentional | 275 // do not fail with exception if stream is empty, it's likely intentional |
278 baseRevisions = new int[0]; | 276 baseRevisions = new int[0]; |
280 } | 278 } |
281 int versionField = da.readInt(); | 279 int versionField = da.readInt(); |
282 da.readInt(); // just to skip next 4 bytes of offset + flags | 280 da.readInt(); // just to skip next 4 bytes of offset + flags |
283 final int INLINEDATA = 1 << 16; | 281 final int INLINEDATA = 1 << 16; |
284 inline = (versionField & INLINEDATA) != 0; | 282 inline = (versionField & INLINEDATA) != 0; |
283 IntVector resBases, resOffsets = null; | |
284 int entryCountGuess = da.length() / REVLOGV1_RECORD_SIZE; | |
285 if (inline) { | |
286 entryCountGuess >>>= 2; // pure guess, assume useful data takes 3/4 of total space | |
287 resOffsets = new IntVector(entryCountGuess, 5000); | |
288 } | |
289 resBases = new IntVector(entryCountGuess, 5000); | |
290 | |
285 long offset = 0; // first offset is always 0, thus Hg uses it for other purposes | 291 long offset = 0; // first offset is always 0, thus Hg uses it for other purposes |
286 while(true) { | 292 while(true) { |
287 int compressedLen = da.readInt(); | 293 int compressedLen = da.readInt(); |
288 // 8+4 = 12 bytes total read here | 294 // 8+4 = 12 bytes total read here |
289 @SuppressWarnings("unused") | 295 @SuppressWarnings("unused") |
307 } else { | 313 } else { |
308 da.skip(3*4 + 32); | 314 da.skip(3*4 + 32); |
309 } | 315 } |
310 if (da.isEmpty()) { | 316 if (da.isEmpty()) { |
311 // fine, done then | 317 // fine, done then |
312 baseRevisions = toArray(resBases); | 318 baseRevisions = resBases.toArray(true); |
313 if (inline) { | 319 if (inline) { |
314 indexRecordOffset = toArray(resOffsets); | 320 indexRecordOffset = resOffsets.toArray(true); |
315 } | 321 } |
316 break; | 322 break; |
317 } else { | 323 } else { |
318 // start reading next record | 324 // start reading next record |
319 long l = da.readLong(); | 325 long l = da.readLong(); |