diff options
author | Ivan Frade <ifrade@google.com> | 2025-06-25 14:05:07 +0300 |
---|---|---|
committer | Ivan Frade <ifrade@google.com> | 2025-06-25 14:05:07 +0300 |
commit | 6f5e28454b0976610880f65ea5f2e375b711979a (patch) | |
tree | 944445db1c7483017638e7362440bd1397635872 | |
parent | 7c7f7d32edc776c02ab5f2caf1e2887feafbde84 (diff) | |
download | jgit-6f5e28454b0976610880f65ea5f2e375b711979a.tar.gz jgit-6f5e28454b0976610880f65ea5f2e375b711979a.zip |
DfsPackFile: Delete #getIndexedObjectSize for ObjectId
This method is inneficient, as callers lookup the object in the
primary index twice: once to find it is in the pack (before calling),
another for the position (in the method). Now we have
\#getIndexedObjectSize(ctx, indexPosition) variant, so callers find the
pack with \#findIdxPosition() and reuse the idxPosition here.
Remove this variant with objectId. It doesn't do anything that the
combination above cannot do.
Change-Id: Ia913f511338b44ab5c45c55d47754d299946f03c
5 files changed, 11 insertions, 36 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollectorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollectorTest.java index 00a3760e21..80bd689084 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollectorTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollectorTest.java @@ -1182,7 +1182,8 @@ public class DfsGarbageCollectorTest { DfsReader reader = odb.newReader(); DfsPackFile gcPack = findFirstBySource(odb.getPacks(), GC); assertTrue(gcPack.hasObjectSizeIndex(reader)); - assertEquals(12, gcPack.getIndexedObjectSize(reader, headsBlob)); + assertEquals(12, gcPack.getIndexedObjectSize(reader, + gcPack.findIdxPosition(reader, headsBlob))); } @Test @@ -1203,7 +1204,8 @@ public class DfsGarbageCollectorTest { DfsReader reader = odb.newReader(); DfsPackFile gcPack = findFirstBySource(odb.getPacks(), GC); assertTrue(gcPack.hasObjectSizeIndex(reader)); - assertEquals(-1, gcPack.getIndexedObjectSize(reader, tooSmallBlob)); + assertEquals(-1, gcPack.getIndexedObjectSize(reader, + gcPack.findIdxPosition(reader, tooSmallBlob))); } @Test diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsInserterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsInserterTest.java index 49f399c38c..efa98de549 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsInserterTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsInserterTest.java @@ -309,7 +309,8 @@ public class DfsInserterTest { assertEquals(PackSource.INSERT, insertPack.getPackDescription().getPackSource()); assertTrue(insertPack.hasObjectSizeIndex(reader)); - assertEquals(contents.length, insertPack.getIndexedObjectSize(reader, fooId)); + assertEquals(contents.length, insertPack.getIndexedObjectSize(reader, + insertPack.findIdxPosition(reader, fooId))); } private static String readString(ObjectLoader loader) throws IOException { diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsPackFileTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsPackFileTest.java index 9680019f88..f2129fd3c5 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsPackFileTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsPackFileTest.java @@ -131,7 +131,8 @@ public class DfsPackFileTest { DfsReader reader = db.getObjectDatabase().newReader(); DfsPackFile pack = db.getObjectDatabase().getPacks()[0]; assertTrue(pack.hasObjectSizeIndex(reader)); - assertEquals(800, pack.getIndexedObjectSize(reader, blobId)); + assertEquals(800, pack.getIndexedObjectSize(reader, + pack.findIdxPosition(reader, blobId))); } @Test diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsPackParserTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsPackParserTest.java index c1cd231c66..9d26978d66 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsPackParserTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsPackParserTest.java @@ -65,6 +65,7 @@ public class DfsPackParserTest { DfsReader reader = repo.getObjectDatabase().newReader(); PackList packList = repo.getObjectDatabase().getPackList(); assertEquals(1, packList.packs.length); - assertEquals(1, packList.packs[0].getIndexedObjectSize(reader, blobA)); + assertEquals(1, packList.packs[0].getIndexedObjectSize(reader, + packList.packs[0].findIdxPosition(reader, blobA))); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java index 564e607439..05b63eaca1 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java @@ -1168,36 +1168,6 @@ public final class DfsPackFile extends BlockBasedFile { /** * Return the size of the object from the object-size index. The object * should be a blob. Any other type is not indexed and returns -1. - * - * Caller MUST be sure that the object is in the pack (e.g. with - * {@link #hasObject(DfsReader, AnyObjectId)}) and the pack has object size - * index (e.g. with {@link #hasObjectSizeIndex(DfsReader)}) before asking - * the indexed size. - * - * @param ctx - * reader context to support reading from the backing store if - * the object size index is not already loaded in memory. - * @param id - * object id of an object in the pack - * @return size of the object from the index. Negative if object is not in - * the index (below threshold or not a blob) - * @throws IOException - * could not read the object size index. IO problem or the pack - * doesn't have it. - */ - long getIndexedObjectSize(DfsReader ctx, AnyObjectId id) - throws IOException { - int idxPosition = idx(ctx).findPosition(id); - if (idxPosition < 0) { - throw new IllegalArgumentException( - "Cannot get size from index since object is not in pack"); //$NON-NLS-1$ - } - return getIndexedObjectSize(ctx, idxPosition); - } - - /** - * Return the size of the object from the object-size index. The object - * should be a blob. Any other type is not indexed and returns -1. * <p> * Caller MUST pass a valid index position, as returned by * {@link #findIdxPosition(DfsReader, AnyObjectId)} and verify the pack has @@ -1219,7 +1189,7 @@ public final class DfsPackFile extends BlockBasedFile { long getIndexedObjectSize(DfsReader ctx, int idxPosition) throws IOException { if (idxPosition < 0) { - throw new IllegalArgumentException("Invalid index position"); + throw new IllegalArgumentException("Invalid index position"); //$NON-NLS-1$ } PackObjectSizeIndex sizeIdx = getObjectSizeIndex(ctx); if (sizeIdx == null) { |