diff options
author | Shawn Pearce <spearce@spearce.org> | 2017-02-26 11:44:51 -0800 |
---|---|---|
committer | Jonathan Nieder <jrn@google.com> | 2017-02-26 15:26:53 -0800 |
commit | 1bf7d3f290ef7dbf9b4f12d15308a4d93042ac83 (patch) | |
tree | dcd13a57b6323daf99673f41174cceac36d7b357 /org.eclipse.jgit.test | |
parent | 0f25f64d4882f7853c9d3dc84ec382d8a78ae646 (diff) | |
download | jgit-1bf7d3f290ef7dbf9b4f12d15308a4d93042ac83.tar.gz jgit-1bf7d3f290ef7dbf9b4f12d15308a4d93042ac83.zip |
SHA1: support reset() and reuse instances
Allow SHA1 instances to be reused to compute another hash value, and
resume caching them in ObjectInserter and PackParser. This shaves a
small amount of running time off parsing git.git's pack file:
before after
------ ------
25.25s 25.55s
25.48s 25.06s
25.26s 24.94s
Almost noise (small difference), but recycling the instances reduces
some stress on the memory allocator finding two 80 word message block
arrays needed for hashing and collision detection.
Change-Id: I4af88a720e81460293bc5c5d1d3db1a831e7e228
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/util/sha1/SHA1Test.java | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/sha1/SHA1Test.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/sha1/SHA1Test.java index c53080455c..8642db79e3 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/sha1/SHA1Test.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/sha1/SHA1Test.java @@ -72,8 +72,13 @@ public class SHA1Test { s.update(new byte[] {}); ObjectId s1 = ObjectId.fromRaw(s.digest()); + s.reset(); + s.update(new byte[] {}); + ObjectId s2 = s.toObjectId(); + assertEquals(m1, s1); assertEquals(exp, s1); + assertEquals(exp, s2); } @Test @@ -89,8 +94,13 @@ public class SHA1Test { s.update(TEST1.getBytes(StandardCharsets.UTF_8)); ObjectId s1 = ObjectId.fromRaw(s.digest()); + s.reset(); + s.update(TEST1.getBytes(StandardCharsets.UTF_8)); + ObjectId s2 = s.toObjectId(); + assertEquals(m1, s1); assertEquals(exp, s1); + assertEquals(exp, s2); } @Test @@ -106,7 +116,12 @@ public class SHA1Test { s.update(TEST2.getBytes(StandardCharsets.UTF_8)); ObjectId s1 = ObjectId.fromRaw(s.digest()); + s.reset(); + s.update(TEST2.getBytes(StandardCharsets.UTF_8)); + ObjectId s2 = s.toObjectId(); + assertEquals(m1, s1); assertEquals(exp, s1); + assertEquals(exp, s2); } } |