From e0c9368f3e7c3857b9b91d12f76dfa09b1540a24 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Fri, 25 Jun 2010 19:21:43 -0700 Subject: [PATCH] Reclaim some bits in ObjectToPack flags field Make the lower bits available for flags that PackWriter can use to keep track of facts about the object. We shouldn't need more than 2^24 delta depths, unpacking that chain is unfathomable anyway. This change gets us 4 bits that are unused in the lower end of the word, which are typically easier to load from Java and most machine instruction sets. We can use these in later changes. Change-Id: Ib9e11221b5bca17c8a531e4ed130ba14c0e3744f Signed-off-by: Shawn O. Pearce --- .../org/eclipse/jgit/lib/ObjectToPack.java | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectToPack.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectToPack.java index dfc3d6f4cf..c0cf8901d9 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectToPack.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectToPack.java @@ -55,6 +55,14 @@ import org.eclipse.jgit.transport.PackedObjectInfo; * each object as they are written to the output stream. */ public class ObjectToPack extends PackedObjectInfo { + private static final int WANT_WRITE = 1 << 0; + + private static final int TYPE_SHIFT = 5; + + private static final int DELTA_SHIFT = 8; + + private static final int NON_DELTA_MASK = 0xff; + /** Other object being packed that this will delta against. */ private ObjectId deltaBase; @@ -62,8 +70,10 @@ public class ObjectToPack extends PackedObjectInfo { * Bit field, from bit 0 to bit 31: * */ private int flags; @@ -78,7 +88,7 @@ public class ObjectToPack extends PackedObjectInfo { */ public ObjectToPack(AnyObjectId src, final int type) { super(src); - flags |= type << 1; + flags = type << TYPE_SHIFT; } /** @@ -151,11 +161,11 @@ public class ObjectToPack extends PackedObjectInfo { } int getType() { - return (flags>>1) & 0x7; + return (flags >> TYPE_SHIFT) & 0x7; } int getDeltaDepth() { - return flags >>> 4; + return flags >>> DELTA_SHIFT; } void updateDeltaDepth() { @@ -166,14 +176,14 @@ public class ObjectToPack extends PackedObjectInfo { d = 1; else d = 0; - flags = (d << 4) | flags & 0x15; + flags = (d << DELTA_SHIFT) | (flags & NON_DELTA_MASK); } boolean wantWrite() { - return (flags & 1) == 1; + return (flags & WANT_WRITE) != 0; } void markWantWrite() { - flags |= 1; + flags |= WANT_WRITE; } } -- 2.39.5