Skip to content

Commit

Permalink
Removes base64 encoding code from LongLib.
Browse files Browse the repository at this point in the history
The code was only used from GWT-RPC client-side and
already copied there.

Change-Id: I1451678542580395fa3fcc199472cbaed72ef9a8
  • Loading branch information
gkdn committed Aug 28, 2015
1 parent de8d164 commit 1788c0b
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 121 deletions.
86 changes: 0 additions & 86 deletions dev/core/super/com/google/gwt/lang/LongLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,22 +187,6 @@ public static boolean gte(LongEmul a, LongEmul b) {
}
}

/**
* Parse a string containing a base-64 encoded version of a long value.
*
* Keep this synchronized with the version in Base64Utils.
*/
public static long longFromBase64(String value) {
int pos = 0;
long longVal = base64Value(value.charAt(pos++));
int len = value.length();
while (pos < len) {
longVal <<= 6;
longVal |= base64Value(value.charAt(pos++));
}
return longVal;
}

public static boolean lt(LongEmul a, LongEmul b) {
return !gte(a, b);
}
Expand Down Expand Up @@ -402,34 +386,6 @@ public static LongEmul sub(LongEmul a, LongEmul b) {
return create(sum0 & MASK, sum1 & MASK, sum2 & MASK_2);
}

/**
* Return an optionally single-quoted string containing a base-64 encoded
* version of the given long value.
*
* Keep this synchronized with the version in Base64Utils.
*/
public static String toBase64(long value) {
// Convert to ints early to avoid need for long ops
int low = (int) (value & 0xffffffff);
int high = (int) (value >> 32);

StringBuilder sb = new StringBuilder();
boolean haveNonZero = base64Append(sb, (high >> 28) & 0xf, false);
haveNonZero = base64Append(sb, (high >> 22) & 0x3f, haveNonZero);
haveNonZero = base64Append(sb, (high >> 16) & 0x3f, haveNonZero);
haveNonZero = base64Append(sb, (high >> 10) & 0x3f, haveNonZero);
haveNonZero = base64Append(sb, (high >> 4) & 0x3f, haveNonZero);
int v = ((high & 0xf) << 2) | ((low >> 30) & 0x3);
haveNonZero = base64Append(sb, v, haveNonZero);
haveNonZero = base64Append(sb, (low >> 24) & 0x3f, haveNonZero);
haveNonZero = base64Append(sb, (low >> 18) & 0x3f, haveNonZero);
haveNonZero = base64Append(sb, (low >> 12) & 0x3f, haveNonZero);
base64Append(sb, (low >> 6) & 0x3f, haveNonZero);
base64Append(sb, low & 0x3f, true);

return sb.toString();
}

public static double toDouble(LongEmul a) {
if (LongLib.lt(a, Const.ZERO)) {
return -toDoubleHelper(LongLib.neg(a));
Expand Down Expand Up @@ -486,48 +442,6 @@ public static LongEmul xor(LongEmul a, LongEmul b) {
return create(getL(a) ^ getL(b), getM(a) ^ getM(b), getH(a) ^ getH(b));
}

private static boolean base64Append(StringBuilder sb, int digit,
boolean haveNonZero) {
if (digit > 0) {
haveNonZero = true;
}
if (haveNonZero) {
int c;
if (digit < 26) {
c = 'A' + digit;
} else if (digit < 52) {
c = 'a' + digit - 26;
} else if (digit < 62) {
c = '0' + digit - 52;
} else if (digit == 62) {
c = '$';
} else {
c = '_';
}
sb.append((char) c);
}
return haveNonZero;
}

// Assume digit is one of [A-Za-z0-9$_]
private static int base64Value(char digit) {
if (digit >= 'A' && digit <= 'Z') {
return digit - 'A';
}
// No need to check digit <= 'z'
if (digit >= 'a') {
return digit - 'a' + 26;
}
if (digit >= '0' && digit <= '9') {
return digit - '0' + 52;
}
if (digit == '$') {
return 62;
}
// digit == '_'
return 63;
}

/**
* Not instantiable.
*/
Expand Down
35 changes: 0 additions & 35 deletions dev/core/test/com/google/gwt/lang/LongLibTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -424,41 +424,6 @@ public static void testAnd() {
doTestBinary(OP_AND);
}

public static void testBase64() {
assertEquals("A", LongLib.toBase64(0x0L));
assertEquals(0x0L, LongLib.longFromBase64("A"));

assertEquals("B", LongLib.toBase64(0x1L));
assertEquals(0x1L, LongLib.longFromBase64("B"));

assertEquals("BA", LongLib.toBase64(0x40L));
assertEquals(0x40L, LongLib.longFromBase64("BA"));

assertEquals("P_________A", LongLib.toBase64(-0x40L));
assertEquals(-0x40L, LongLib.longFromBase64("P_________A"));

assertEquals("P__________", LongLib.toBase64(-1L));
assertEquals(-1L, LongLib.longFromBase64("P__________"));

// Use all types of base 64 chars
long value = 0L;
value |= 15L << 60; // 'P'
value |= 35L << 54; // 'j'
value |= 44L << 48; // 's'
value |= 62L << 42; // '$'
value |= 26L << 36; // 'a'
value |= 9L << 30; // 'J'
value |= 18L << 24; // 'S'
value |= 25L << 18; // 'Z'
value |= 52L << 12; // '0'
value |= 57L << 6; // '5'
value |= 63L; // '_'

String s = "Pjs$aJSZ05_";
assertEquals(s, LongLib.toBase64(value));
assertEquals(value, LongLib.longFromBase64(s));
}

public static void testCompare() {
doTestCompare(OP_COMPARE);
}
Expand Down

0 comments on commit 1788c0b

Please sign in to comment.