From 01a0699acc09bc10646411bdd7cd1cf8004f7d65 Mon Sep 17 00:00:00 2001 From: Shawn Pearce Date: Fri, 5 Apr 2013 09:42:29 -0700 Subject: [PATCH] Micro-optimize reuseDeltaFor in PackWriter This switch is called mostly for OBJ_TREE and OBJ_BLOB types, which typically make up 66% of the objects in a repository. Simplify the test for these common types by testing for the one bit they have in common and returning early. Object type 5 is currently undefined. In the old code it would hit the default and return true. In the new code it will match the early case and also return true. In either implementation 5 should never show up as it is not a valid type known to Git. Object type 6 OFS_DELTA is not permitted to be supplied here. Object type 7 REF_DELTA is not permitted to be supplied here. Change-Id: I0ede8acee928bb3e73c744450863942064864e9c --- .../jgit/internal/storage/pack/PackWriter.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java index feb5bbc836..34bf0eb16b 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java @@ -2020,18 +2020,14 @@ public class PackWriter { } private boolean reuseDeltaFor(ObjectToPack otp) { - switch (otp.getType()) { - case Constants.OBJ_COMMIT: - return reuseDeltaCommits; - case Constants.OBJ_TREE: - return true; - case Constants.OBJ_BLOB: + int type = otp.getType(); + if ((type & 2) != 0) // OBJ_TREE(2) or OBJ_BLOB(3) return true; - case Constants.OBJ_TAG: + if (type == OBJ_COMMIT) + return reuseDeltaCommits; + if (type == OBJ_TAG) return false; - default: - return true; - } + return true; } /** Summary of how PackWriter created the pack. */ -- 2.39.5