comparison src/org/tmatesoft/hg/internal/RevlogStream.java @ 594:cc7b0c4dc993

Cache only in-memory revision representations
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 02 May 2013 19:22:43 +0200
parents 9619301a7bb9
children 5daa42067e7c
comparison
equal deleted inserted replaced
593:9619301a7bb9 594:cc7b0c4dc993
321 throw new HgInvalidRevisionException(String.format("Can't iterate [%d, %d] in range [0..%d]", sortedRevisions[0], sortedRevisions[sortedRevisions.length - 1], indexSize), null, sortedRevisions[sortedRevisions.length - 1]); 321 throw new HgInvalidRevisionException(String.format("Can't iterate [%d, %d] in range [0..%d]", sortedRevisions[0], sortedRevisions[sortedRevisions.length - 1], indexSize), null, sortedRevisions[sortedRevisions.length - 1]);
322 } 322 }
323 323
324 ReaderN1 r = new ReaderN1(needData, inspector, dataAccess.shallMergePatches()); 324 ReaderN1 r = new ReaderN1(needData, inspector, dataAccess.shallMergePatches());
325 try { 325 try {
326 r.start(sortedRevisions.length, lastRevisionRead == null ? null : lastRevisionRead.get()); 326 r.start(sortedRevisions.length, getLastRevisionRead());
327 for (int i = 0; i < sortedRevisions.length; ) { 327 for (int i = 0; i < sortedRevisions.length; ) {
328 int x = i; 328 int x = i;
329 i++; 329 i++;
330 while (i < sortedRevisions.length) { 330 while (i < sortedRevisions.length) {
331 if (sortedRevisions[i] == sortedRevisions[i-1] + 1) { 331 if (sortedRevisions[i] == sortedRevisions[i-1] + 1) {
569 569
570 // invoked only once per instance 570 // invoked only once per instance
571 public CachedRevision finish() { 571 public CachedRevision finish() {
572 CachedRevision rv = null; 572 CachedRevision rv = null;
573 if (lastUserData != null) { 573 if (lastUserData != null) {
574 rv = new CachedRevision(lastRevisionRead, lastUserData); 574 if (lastUserData instanceof ByteArrayDataAccess) {
575 // it's safe to cache only in-memory revision texts,
576 // if lastUserData is merely a filter over file stream,
577 // we'd need to keep file open, and this is bad.
578 // XXX perhaps, wrap any DataAccess.byteArray into
579 // ByteArrayDataAccess?
580 rv = new CachedRevision(lastRevisionRead, lastUserData);
581 } else {
582 lastUserData.done();
583 }
575 lastUserData = null; 584 lastUserData = null;
576 } 585 }
577 if (lifecycleListener != null) { 586 if (lifecycleListener != null) {
578 lifecycleListener.finish(cb); 587 lifecycleListener.finish(cb);
579 lifecycleListener = null; 588 lifecycleListener = null;