Using new Integer(int) is guaranteed to always result in a new object whereas Integer.valueOf(int) allows caching of values to be done by the compiler, class library, or JVM. Using of cached values avoids object allocation and the code will be faster. Values between -128 and 127 are guaranteed to have corresponding cached instances and using valueOf is approximately 3.5 times faster than using constructor. For values outside the constant range the performance of both styles is the same. Unless the class must be compatible with JVMs predating Java 1.5, use either autoboxing or the valueOf() method when creating instances of Long, Integer, Short, Character, and Byte. Signed-off-by: Matthias Sohn <matthias.sohn@xxxxxxx> --- .../src/org/spearce/jgit/transport/IndexPack.java | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/IndexPack.java b/org.spearce.jgit/src/org/spearce/jgit/transport/IndexPack.java index e0e4855..04ef59d 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/transport/IndexPack.java +++ b/org.spearce.jgit/src/org/spearce/jgit/transport/IndexPack.java @@ -383,7 +383,7 @@ private void resolveDeltas(final ProgressMonitor progress) private void resolveDeltas(final PackedObjectInfo oe) throws IOException { final int oldCRC = oe.getCRC(); if (baseById.containsKey(oe) - || baseByPos.containsKey(new Long(oe.getOffset()))) + || baseByPos.containsKey(Long.valueOf(oe.getOffset()))) resolveDeltas(oe.getOffset(), oldCRC, Constants.OBJ_BAD, null, oe); } @@ -448,7 +448,7 @@ private void resolveDeltas(final long pos, final int oldCRC, int type, private void resolveChildDeltas(final long pos, int type, byte[] data, PackedObjectInfo oe) throws IOException { final ArrayList<UnresolvedDelta> a = baseById.remove(oe); - final ArrayList<UnresolvedDelta> b = baseByPos.remove(new Long(pos)); + final ArrayList<UnresolvedDelta> b = baseByPos.remove(Long.valueOf(pos)); int ai = 0, bi = 0; if (a != null && b != null) { while (ai < a.size() && bi < b.size()) { @@ -679,7 +679,7 @@ private void indexOneObject() throws IOException { ofs <<= 7; ofs += (c & 127); } - final Long base = new Long(pos - ofs); + final Long base = Long.valueOf(pos - ofs); ArrayList<UnresolvedDelta> r = baseByPos.get(base); if (r == null) { r = new ArrayList<UnresolvedDelta>(8); -- 1.6.2.2.1669.g7eaf8 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html