]> source.dussan.org Git - jgit.git/commitdiff
Refactor: Make retriveCompressed an method of the Bitmap class 22/157522/7
authorYunjie Li <yunjieli@google.com>
Mon, 10 Feb 2020 23:22:31 +0000 (15:22 -0800)
committerYunjie Li <yunjieli@google.com>
Wed, 13 May 2020 00:32:05 +0000 (17:32 -0700)
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>
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/BitmapIndexImpl.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackBitmapIndexBuilder.java
org.eclipse.jgit/src/org/eclipse/jgit/lib/BitmapIndex.java

index 6aa1a0e8eaba819da376b801195449ac842698b8..0d3a2b4f12c01d52214f8367abe8b7c724c30445 100644 (file)
@@ -252,6 +252,11 @@ public class BitmapIndexImpl implements BitmapIndex {
                        return bitmapIndex;
                }
 
+               @Override
+               public EWAHCompressedBitmap retrieveCompressed() {
+                       return build().retrieveCompressed();
+               }
+
                private EWAHCompressedBitmap ewahBitmap(Bitmap other) {
                        if (other instanceof CompressedBitmap) {
                                CompressedBitmap b = (CompressedBitmap) other;
@@ -372,7 +377,8 @@ public class BitmapIndexImpl implements BitmapIndex {
                        };
                }
 
-               EWAHCompressedBitmap getEwahCompressedBitmap() {
+               @Override
+               public EWAHCompressedBitmap retrieveCompressed() {
                        return bitmap;
                }
 
index 9538cc5e0a2bb9327471a386c499b1ba2d92a21c..d87b6996f7cb9729b09b11863d72d5fb418d074c 100644 (file)
@@ -17,11 +17,9 @@ import java.util.List;
 import java.util.NoSuchElementException;
 
 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.lib.AnyObjectId;
 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.ObjectId;
 import org.eclipse.jgit.lib.ObjectIdOwnerMap;
@@ -134,16 +132,7 @@ public class PackBitmapIndexBuilder extends BasePackBitmapIndex {
         *            the flags to be stored with the bitmap
         */
        public void addBitmap(AnyObjectId objectId, Bitmap bitmap, int flags) {
-               if (bitmap instanceof BitmapBuilder)
-                       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);
+               addBitmap(objectId, bitmap.retrieveCompressed(), flags);
        }
 
        /**
index f61286d6da92443367b4f507185bbc97d9ba9947..f6695bdf7d050dc11e4e7a731519af859085e3ee 100644 (file)
@@ -14,6 +14,8 @@ import java.util.Iterator;
 
 import org.eclipse.jgit.internal.storage.file.PackBitmapIndex;
 
+import com.googlecode.javaewah.EWAHCompressedBitmap;
+
 /**
  * A compressed bitmap representation of the entire object graph.
  *
@@ -81,6 +83,14 @@ public interface BitmapIndex {
                 */
                @Override
                Iterator<BitmapObject> iterator();
+
+               /**
+                * Returns the corresponding raw compressed EWAH bitmap of the bitmap.
+                * 
+                * @return the corresponding {@code EWAHCompressedBitmap}
+                * @since 5.8
+                */
+               EWAHCompressedBitmap retrieveCompressed();
        }
 
        /**