From: Robin Rosenberg <robin.rosenberg@dewire.com>
To: "Shawn O. Pearce" <spearce@spearce.org>
Cc: git@vger.kernel.org,
"Roger C. Soares" <rogersoares@intelinet.com.br>,
Dave Watson <dwatson@mimvista.com>
Subject: [EGIT PATCH 2/2] Use Integer.valueOf instead of new Integer
Date: Wed, 6 Feb 2008 21:15:37 +0100 [thread overview]
Message-ID: <200802062115.38212.robin.rosenberg@dewire.com> (raw)
In-Reply-To: <20080206070631.GM24004@spearce.org>
onsdagen den 6 februari 2008 skrev Shawn O. Pearce:
> Use Integer.valueOf(int). Post Java 5 implementations of the J2SE
> are required to cache values between -128 and 127 (inclusive).
>
> Actually, when the Java compiler autoboxes values it does so through
> these static valueOf methods, which were mostly introduced as part
> of the Java 5 API updates. For small common values its cached and
> will thus avoid garbage generation, for less common values it goes
> back to allocating the object.
Thank you for this information.
-- robin
>From 2f2248fc01c169d85e88d42d10693e4ec59a0c1d Mon Sep 17 00:00:00 2001
From: Robin Rosenberg <robin.rosenberg@dewire.com>
Date: Wed, 6 Feb 2008 21:06:08 +0100
Subject: [EGIT PATCH 2/2] Use Integer.valueOf instead of new Integer
Java 1.5+ has a cache for small numbers.
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
---
.../src/org/spearce/egit/ui/FindResults.java | 10 +++++-----
.../internal/decorators/GitResourceDecorator.java | 4 ++--
.../tst/org/spearce/jgit/lib/MappedListTest.java | 8 ++++----
.../tst/org/spearce/jgit/lib/SuperListTest.java | 12 ++++++------
.../src/org/spearce/jgit/lib/SuperList.java | 2 +-
.../org/spearce/jgit/lib/TopologicalSorter.java | 8 ++++----
6 files changed, 22 insertions(+), 22 deletions(-)
Thanks to Shawn
-- robin
diff --git a/org.spearce.egit.ui/src/org/spearce/egit/ui/FindResults.java b/org.spearce.egit.ui/src/org/spearce/egit/ui/FindResults.java
index 9484503..2b49597 100644
--- a/org.spearce.egit.ui/src/org/spearce/egit/ui/FindResults.java
+++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/FindResults.java
@@ -45,7 +45,7 @@ public class FindResults {
* <code>false</code> otherwise
*/
public synchronized boolean isFoundAt(int index) {
- return matchesMap.containsKey(new Integer(index));
+ return matchesMap.containsKey(Integer.valueOf(index));
}
/**
@@ -59,7 +59,7 @@ public class FindResults {
*/
public synchronized int getIndexAfter(int index) {
Integer[] matches = getkeysArray();
- int sres = Arrays.binarySearch(matches, new Integer(index));
+ int sres = Arrays.binarySearch(matches, Integer.valueOf(index));
if (sres >= 0 && sres != matches.length - 1) {
return matches[sres + 1].intValue();
} else if (sres < 0) {
@@ -83,7 +83,7 @@ public class FindResults {
*/
public synchronized int getIndexBefore(int index) {
Integer[] matches = getkeysArray();
- int sres = Arrays.binarySearch(matches, new Integer(index));
+ int sres = Arrays.binarySearch(matches, Integer.valueOf(index));
if (sres >= 0 && sres != 0) {
return matches[sres - 1].intValue();
} else if (sres < -1) {
@@ -136,7 +136,7 @@ public class FindResults {
* list. Returns -1 if <code>index</code> doesn't contain a match
*/
public synchronized int getMatchNumberFor(int index) {
- Integer ix = matchesMap.get(new Integer(index));
+ Integer ix = matchesMap.get(Integer.valueOf(index));
if (ix != null) {
return ix.intValue();
}
@@ -168,7 +168,7 @@ public class FindResults {
* the history table item index that matches a find pattern.
*/
public synchronized void add(int matchIx) {
- matchesMap.put(new Integer(matchIx), new Integer(++matchesCount));
+ matchesMap.put(Integer.valueOf(matchIx), Integer.valueOf(++matchesCount));
keysArray = null;
}
diff --git a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/GitResourceDecorator.java
b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/GitResourceDecorator.java
index 9592817..df2f569 100644
--- a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/GitResourceDecorator.java
+++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/GitResourceDecorator.java
@@ -358,7 +358,7 @@ public class GitResourceDecorator extends LabelProvider implements
try {
Integer dirty = (Integer) rsrc.getSessionProperty(GITFOLDERDIRTYSTATEPROPERTY);
if (dirty == null) {
- rsrc.setSessionProperty(GITFOLDERDIRTYSTATEPROPERTY, new Integer(flag));
+ rsrc.setSessionProperty(GITFOLDERDIRTYSTATEPROPERTY, Integer.valueOf(flag));
Activator.trace("SETTING:"+rsrc.getFullPath().toOSString()+" => "+flag);
orState(rsrc.getParent(), flag);
Display.getDefault().asyncExec(new Runnable() {
@@ -375,7 +375,7 @@ public class GitResourceDecorator extends LabelProvider implements
});
} else {
if ((dirty.intValue() | flag) != dirty.intValue()) {
- dirty = new Integer(dirty.intValue() | flag);
+ dirty = Integer.valueOf(dirty.intValue() | flag);
rsrc.setSessionProperty(GITFOLDERDIRTYSTATEPROPERTY, dirty);
Activator.trace("SETTING:"+rsrc.getFullPath().toOSString()+" => "+dirty);
orState(rsrc.getParent(), dirty.intValue());
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/MappedListTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/MappedListTest.java
index ccc13a0..6513d99 100644
--- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/MappedListTest.java
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/MappedListTest.java
@@ -29,13 +29,13 @@ public class MappedListTest extends TestCase {
new Float(3.14f) })) {
@Override
protected Integer map(Float from) {
- return new Integer((int) from.floatValue() * 2);
+ return Integer.valueOf((int) from.floatValue() * 2);
}
};
assertEquals(3, x.toArray().length);
- assertEquals(new Integer(2), x.toArray()[0]);
- assertEquals(new Integer(4), x.toArray()[1]);
- assertEquals(new Integer(6), x.toArray()[2]);
+ assertEquals(Integer.valueOf(2), x.toArray()[0]);
+ assertEquals(Integer.valueOf(4), x.toArray()[1]);
+ assertEquals(Integer.valueOf(6), x.toArray()[2]);
}
}
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/SuperListTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/SuperListTest.java
index 79f4da6..be38b95 100644
--- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/SuperListTest.java
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/SuperListTest.java
@@ -38,14 +38,14 @@ public class SuperListTest extends TestCase {
l.addAll(sl1);
l.addAll(sl2);
l.addAll(sl3);
- l.add(new Integer(7));
+ l.add(Integer.valueOf(7));
assertEquals(5, l.size());
- assertEquals(new Integer(3), l.toArray()[0]);
- assertEquals(new Integer(4), l.toArray()[1]);
- assertEquals(new Integer(5), l.toArray()[2]);
- assertEquals(new Integer(6), l.toArray()[3]);
- assertEquals(new Integer(7), l.toArray()[4]);
+ assertEquals(Integer.valueOf(3), l.toArray()[0]);
+ assertEquals(Integer.valueOf(4), l.toArray()[1]);
+ assertEquals(Integer.valueOf(5), l.toArray()[2]);
+ assertEquals(Integer.valueOf(6), l.toArray()[3]);
+ assertEquals(Integer.valueOf(7), l.toArray()[4]);
assertEquals(5, l.toArray().length);
}
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/SuperList.java b/org.spearce.jgit/src/org/spearce/jgit/lib/SuperList.java
index 4a50794..04c9958 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/SuperList.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/SuperList.java
@@ -48,7 +48,7 @@ public class SuperList<T> extends AbstractList<T> {
*/
public boolean addAll(List<T> subList) {
int lastEnd = subLists.size() > 0 ? subListEnd.get(subListEnd.size()-1).intValue() : 0;
- subListEnd.add(new Integer(lastEnd + subList.size()));
+ subListEnd.add(Integer.valueOf(lastEnd + subList.size()));
subLists.add(subList);
return true;
}
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/TopologicalSorter.java b/org.spearce.jgit/src/org/spearce/jgit/lib/TopologicalSorter.java
index c33334e..d5c2430 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/TopologicalSorter.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/TopologicalSorter.java
@@ -205,9 +205,9 @@ public class TopologicalSorter<T> {
allNodes.add(edge.to);
Integer n = inCount.get(edge.to);
if (n == null)
- inCount.put(edge.to, new Integer(1));
+ inCount.put(edge.to, Integer.valueOf(1));
else
- inCount.put(edge.to, new Integer(n.intValue() + 1));
+ inCount.put(edge.to, Integer.valueOf(n.intValue() + 1));
}
/**
@@ -255,7 +255,7 @@ public class TopologicalSorter<T> {
zeroIn.add(e.to);
inCount.remove(e.to);
} else {
- inCount.put(e.to, new Integer(c.intValue() - 1));
+ inCount.put(e.to, Integer.valueOf(c.intValue() - 1));
}
}
// allEdges.remove(from);
@@ -356,7 +356,7 @@ public class TopologicalSorter<T> {
}
Iterator<T> i = zeroIn.iterator();
ret = i.next();
- internalOrder.put(ret, new Integer(internalOrder.size()));
+ internalOrder.put(ret, Integer.valueOf(internalOrder.size()));
i.remove();
removeallfrom(ret);
return ret;
--
1.5.4.rc4.25.g81cc
next prev parent reply other threads:[~2008-02-06 20:16 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-05 0:15 [EGIT PATCH Series] Cleanups and javadocs Robin Rosenberg
2008-02-05 0:15 ` [EGIT PATCH 1/6] Comment some empty blocks that should be empty Robin Rosenberg
2008-02-05 0:15 ` [EGIT PATCH 2/6] Cleanup unboxing/boxing Robin Rosenberg
2008-02-05 0:15 ` [EGIT PATCH 3/6] Do not require javadoc in egit.core test project Robin Rosenberg
2008-02-05 0:15 ` [EGIT PATCH 4/6] Javadoc update for Egit Robin Rosenberg
2008-02-05 0:15 ` [EGIT PATCH 5/6] Drop unused GitBlobStorage class Robin Rosenberg
2008-02-05 0:15 ` [EGIT PATCH 6/6] Tighten requirements on javadoc Robin Rosenberg
2008-02-06 7:06 ` [EGIT PATCH 2/6] Cleanup unboxing/boxing Shawn O. Pearce
2008-02-06 20:14 ` [EGIT PATCH 1/2] Use Boolean.valueOf instead of new Boolean Robin Rosenberg
2008-02-06 20:15 ` Robin Rosenberg [this message]
2008-02-08 2:52 ` [EGIT PATCH 2/2] Use Integer.valueOf instead of new Integer Roger C. Soares
2008-02-05 15:09 ` [EGIT PATCH Series] Cleanups and javadocs Roger C. Soares
2008-02-05 21:47 ` Robin Rosenberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200802062115.38212.robin.rosenberg@dewire.com \
--to=robin.rosenberg@dewire.com \
--cc=dwatson@mimvista.com \
--cc=git@vger.kernel.org \
--cc=rogersoares@intelinet.com.br \
--cc=spearce@spearce.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).