From: Yann Simon <yann.simon.fr@gmail.com>
To: Robin Rosenberg <robin.rosenberg.lists@dewire.com>,
"Shawn O. Pearce" <spearce@spearce.org>
Cc: git <git@vger.kernel.org>
Subject: [JGIT] Questions about binary right shifting
Date: Thu, 05 Feb 2009 15:37:37 +0100 [thread overview]
Message-ID: <498AF9B1.1060200@gmail.com> (raw)
Hi,
I can see in the code that the signed right shifting is used.
Could it be a problem? Or do we manipulate only positive numbers?
diff --git a/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCache.java b/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCache.java
index 8eb4022..d70eca0 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCache.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCache.java
@@ -577,7 +577,7 @@ int findEntry(final byte[] p, final int pLen) {
int low = 0;
int high = entryCnt;
do {
- int mid = (low + high) >> 1;
+ int mid = (low + high) >>> 1;
final int cmp = cmp(p, pLen, sortedEntries[mid]);
if (cmp < 0)
high = mid;
And could we used right shifting to optimize a division per 2?
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/Tree.java b/org.spearce.jgit/src/org/spearce/jgit/lib/Tree.java
index 0ecd04d..ff9e666 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/Tree.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Tree.java
@@ -136,7 +136,7 @@ private static final int binarySearch(final TreeEntry[] entries,
int high = entries.length;
int low = 0;
do {
- final int mid = (low + high) / 2;
+ final int mid = (low + high) >>> 1;
final int cmp = compareNames(entries[mid].getNameUTF8(), nameUTF8,
nameStart, nameEnd, TreeEntry.lastChar(entries[mid]), nameUTF8last);
if (cmp < 0)
Yann
next reply other threads:[~2009-02-05 14:39 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-05 14:37 Yann Simon [this message]
2009-02-05 15:21 ` [JGIT] Questions about binary right shifting Shawn O. Pearce
2009-02-05 20:32 ` 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=498AF9B1.1060200@gmail.com \
--to=yann.simon.fr@gmail.com \
--cc=git@vger.kernel.org \
--cc=robin.rosenberg.lists@dewire.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.