Browse Source

Refactor: Make retriveCompressed an method of the Bitmap class

Make retrieveCompressed() a method of Bitmap interface to avoid type
casting and later reuse in improving the memory footprint of GC's bitmap
generation phase.

Change-Id: I098d85105cf17af845d43b8c71b4ca48b02fd7da
Signed-off-by: Yunjie Li <yunjieli@google.com>
master
Yunjie Li 5 years ago
parent
commit
840e414d0b
  1. 8
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/BitmapIndexImpl.java
  2. 13
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackBitmapIndexBuilder.java
  3. 10
      org.eclipse.jgit/src/org/eclipse/jgit/lib/BitmapIndex.java

8
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/BitmapIndexImpl.java

@ -252,6 +252,11 @@ public class BitmapIndexImpl implements BitmapIndex {
return bitmapIndex; return bitmapIndex;
} }
@Override
public EWAHCompressedBitmap retrieveCompressed() {
return build().retrieveCompressed();
}
private EWAHCompressedBitmap ewahBitmap(Bitmap other) { private EWAHCompressedBitmap ewahBitmap(Bitmap other) {
if (other instanceof CompressedBitmap) { if (other instanceof CompressedBitmap) {
CompressedBitmap b = (CompressedBitmap) other; CompressedBitmap b = (CompressedBitmap) other;
@ -372,7 +377,8 @@ public class BitmapIndexImpl implements BitmapIndex {
}; };
} }
EWAHCompressedBitmap getEwahCompressedBitmap() { @Override
public EWAHCompressedBitmap retrieveCompressed() {
return bitmap; return bitmap;
} }

13
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackBitmapIndexBuilder.java

@ -17,11 +17,9 @@ import java.util.List;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import org.eclipse.jgit.internal.JGitText; import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.internal.storage.file.BitmapIndexImpl.CompressedBitmap;
import org.eclipse.jgit.internal.storage.pack.ObjectToPack; import org.eclipse.jgit.internal.storage.pack.ObjectToPack;
import org.eclipse.jgit.lib.AnyObjectId; import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.BitmapIndex.Bitmap; import org.eclipse.jgit.lib.BitmapIndex.Bitmap;
import org.eclipse.jgit.lib.BitmapIndex.BitmapBuilder;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectIdOwnerMap; import org.eclipse.jgit.lib.ObjectIdOwnerMap;
@ -134,16 +132,7 @@ public class PackBitmapIndexBuilder extends BasePackBitmapIndex {
* the flags to be stored with the bitmap * the flags to be stored with the bitmap
*/ */
public void addBitmap(AnyObjectId objectId, Bitmap bitmap, int flags) { public void addBitmap(AnyObjectId objectId, Bitmap bitmap, int flags) {
if (bitmap instanceof BitmapBuilder) addBitmap(objectId, bitmap.retrieveCompressed(), flags);
bitmap = ((BitmapBuilder) bitmap).build();
EWAHCompressedBitmap compressed;
if (bitmap instanceof CompressedBitmap)
compressed = ((CompressedBitmap) bitmap).getEwahCompressedBitmap();
else
throw new IllegalArgumentException(bitmap.getClass().toString());
addBitmap(objectId, compressed, flags);
} }
/** /**

10
org.eclipse.jgit/src/org/eclipse/jgit/lib/BitmapIndex.java

@ -14,6 +14,8 @@ import java.util.Iterator;
import org.eclipse.jgit.internal.storage.file.PackBitmapIndex; import org.eclipse.jgit.internal.storage.file.PackBitmapIndex;
import com.googlecode.javaewah.EWAHCompressedBitmap;
/** /**
* A compressed bitmap representation of the entire object graph. * A compressed bitmap representation of the entire object graph.
* *
@ -81,6 +83,14 @@ public interface BitmapIndex {
*/ */
@Override @Override
Iterator<BitmapObject> iterator(); Iterator<BitmapObject> iterator();
/**
* Returns the corresponding raw compressed EWAH bitmap of the bitmap.
*
* @return the corresponding {@code EWAHCompressedBitmap}
* @since 5.8
*/
EWAHCompressedBitmap retrieveCompressed();
} }
/** /**

Loading…
Cancel
Save