fixed 3727: simplify collation key comparison in java

X-SVN-Rev: 15132
This commit is contained in:
Doug Felt 2004-05-03 22:47:06 +00:00
parent eba142ffeb
commit 9823663e2d
2 changed files with 22 additions and 65 deletions

View File

@ -246,39 +246,17 @@ public final class CollationKey implements Comparable
*/
public int compareTo(CollationKey target)
{
// syn wee todo check if there's a unsigned byte comparison
int i = 0;
while (m_key_[i] != 0 && target.m_key_[i] != 0) {
byte key = m_key_[i];
byte targetkey = target.m_key_[i];
if (key == targetkey) {
i ++;
continue;
}
if (key >= 0) {
if (targetkey < 0 || key < targetkey) {
return -1;
}
// target key has to be positive and less than key
return 1;
}
else {
// key is negative
if (targetkey >= 0 || key > targetkey) {
return 1;
}
return -1;
}
}
// last comparison if we encounter a 0
if (m_key_[i] == target.m_key_[i]) {
return 0;
}
if (m_key_[i] == 0) {
return -1;
}
// target is 0
return 1;
for (int i = 0;; ++i) {
int l = m_key_[i]&0xff;
int r = target.m_key_[i]&0xff;
if (l < r) {
return -1;
} else if (l > r) {
return 1;
} else if (l == 0) {
return 0;
}
}
}
/**

View File

@ -110,37 +110,16 @@ public final class RawCollationKey extends ByteArrayWrapper
*/
public int compareTo(RawCollationKey target)
{
int i = 0;
while (bytes[i] != 0 && target.bytes[i] != 0) {
byte key = bytes[i];
byte targetkey = target.bytes[i];
if (key == targetkey) {
i ++;
continue;
}
if (key >= 0) {
if (targetkey < 0 || key < targetkey) {
return -1;
}
// target key has to be positive and less than key
return 1;
}
else {
// key is negative
if (targetkey >= 0 || key > targetkey) {
return 1;
}
return -1;
}
}
// last comparison if we encounter a 0
if (bytes[i] == target.bytes[i]) {
return 0;
}
if (bytes[i] == 0) {
return -1;
}
// target is 0
return 1;
for (int i = 0;; ++i) {
int l = bytes[i]&0xff;
int r = target.bytes[i]&0xff;
if (l < r) {
return -1;
} else if (l > r) {
return 1;
} else if (l == 0) {
return 0;
}
}
}
}