Skip to content

Commit 1788c0b

Browse files
committed
Removes base64 encoding code from LongLib.
The code was only used from GWT-RPC client-side and already copied there. Change-Id: I1451678542580395fa3fcc199472cbaed72ef9a8
1 parent de8d164 commit 1788c0b

File tree

2 files changed

+0
-121
lines changed

2 files changed

+0
-121
lines changed

dev/core/super/com/google/gwt/lang/LongLib.java

-86
Original file line numberDiff line numberDiff line change
@@ -187,22 +187,6 @@ public static boolean gte(LongEmul a, LongEmul b) {
187187
}
188188
}
189189

190-
/**
191-
* Parse a string containing a base-64 encoded version of a long value.
192-
*
193-
* Keep this synchronized with the version in Base64Utils.
194-
*/
195-
public static long longFromBase64(String value) {
196-
int pos = 0;
197-
long longVal = base64Value(value.charAt(pos++));
198-
int len = value.length();
199-
while (pos < len) {
200-
longVal <<= 6;
201-
longVal |= base64Value(value.charAt(pos++));
202-
}
203-
return longVal;
204-
}
205-
206190
public static boolean lt(LongEmul a, LongEmul b) {
207191
return !gte(a, b);
208192
}
@@ -402,34 +386,6 @@ public static LongEmul sub(LongEmul a, LongEmul b) {
402386
return create(sum0 & MASK, sum1 & MASK, sum2 & MASK_2);
403387
}
404388

405-
/**
406-
* Return an optionally single-quoted string containing a base-64 encoded
407-
* version of the given long value.
408-
*
409-
* Keep this synchronized with the version in Base64Utils.
410-
*/
411-
public static String toBase64(long value) {
412-
// Convert to ints early to avoid need for long ops
413-
int low = (int) (value & 0xffffffff);
414-
int high = (int) (value >> 32);
415-
416-
StringBuilder sb = new StringBuilder();
417-
boolean haveNonZero = base64Append(sb, (high >> 28) & 0xf, false);
418-
haveNonZero = base64Append(sb, (high >> 22) & 0x3f, haveNonZero);
419-
haveNonZero = base64Append(sb, (high >> 16) & 0x3f, haveNonZero);
420-
haveNonZero = base64Append(sb, (high >> 10) & 0x3f, haveNonZero);
421-
haveNonZero = base64Append(sb, (high >> 4) & 0x3f, haveNonZero);
422-
int v = ((high & 0xf) << 2) | ((low >> 30) & 0x3);
423-
haveNonZero = base64Append(sb, v, haveNonZero);
424-
haveNonZero = base64Append(sb, (low >> 24) & 0x3f, haveNonZero);
425-
haveNonZero = base64Append(sb, (low >> 18) & 0x3f, haveNonZero);
426-
haveNonZero = base64Append(sb, (low >> 12) & 0x3f, haveNonZero);
427-
base64Append(sb, (low >> 6) & 0x3f, haveNonZero);
428-
base64Append(sb, low & 0x3f, true);
429-
430-
return sb.toString();
431-
}
432-
433389
public static double toDouble(LongEmul a) {
434390
if (LongLib.lt(a, Const.ZERO)) {
435391
return -toDoubleHelper(LongLib.neg(a));
@@ -486,48 +442,6 @@ public static LongEmul xor(LongEmul a, LongEmul b) {
486442
return create(getL(a) ^ getL(b), getM(a) ^ getM(b), getH(a) ^ getH(b));
487443
}
488444

489-
private static boolean base64Append(StringBuilder sb, int digit,
490-
boolean haveNonZero) {
491-
if (digit > 0) {
492-
haveNonZero = true;
493-
}
494-
if (haveNonZero) {
495-
int c;
496-
if (digit < 26) {
497-
c = 'A' + digit;
498-
} else if (digit < 52) {
499-
c = 'a' + digit - 26;
500-
} else if (digit < 62) {
501-
c = '0' + digit - 52;
502-
} else if (digit == 62) {
503-
c = '$';
504-
} else {
505-
c = '_';
506-
}
507-
sb.append((char) c);
508-
}
509-
return haveNonZero;
510-
}
511-
512-
// Assume digit is one of [A-Za-z0-9$_]
513-
private static int base64Value(char digit) {
514-
if (digit >= 'A' && digit <= 'Z') {
515-
return digit - 'A';
516-
}
517-
// No need to check digit <= 'z'
518-
if (digit >= 'a') {
519-
return digit - 'a' + 26;
520-
}
521-
if (digit >= '0' && digit <= '9') {
522-
return digit - '0' + 52;
523-
}
524-
if (digit == '$') {
525-
return 62;
526-
}
527-
// digit == '_'
528-
return 63;
529-
}
530-
531445
/**
532446
* Not instantiable.
533447
*/

dev/core/test/com/google/gwt/lang/LongLibTest.java

-35
Original file line numberDiff line numberDiff line change
@@ -424,41 +424,6 @@ public static void testAnd() {
424424
doTestBinary(OP_AND);
425425
}
426426

427-
public static void testBase64() {
428-
assertEquals("A", LongLib.toBase64(0x0L));
429-
assertEquals(0x0L, LongLib.longFromBase64("A"));
430-
431-
assertEquals("B", LongLib.toBase64(0x1L));
432-
assertEquals(0x1L, LongLib.longFromBase64("B"));
433-
434-
assertEquals("BA", LongLib.toBase64(0x40L));
435-
assertEquals(0x40L, LongLib.longFromBase64("BA"));
436-
437-
assertEquals("P_________A", LongLib.toBase64(-0x40L));
438-
assertEquals(-0x40L, LongLib.longFromBase64("P_________A"));
439-
440-
assertEquals("P__________", LongLib.toBase64(-1L));
441-
assertEquals(-1L, LongLib.longFromBase64("P__________"));
442-
443-
// Use all types of base 64 chars
444-
long value = 0L;
445-
value |= 15L << 60; // 'P'
446-
value |= 35L << 54; // 'j'
447-
value |= 44L << 48; // 's'
448-
value |= 62L << 42; // '$'
449-
value |= 26L << 36; // 'a'
450-
value |= 9L << 30; // 'J'
451-
value |= 18L << 24; // 'S'
452-
value |= 25L << 18; // 'Z'
453-
value |= 52L << 12; // '0'
454-
value |= 57L << 6; // '5'
455-
value |= 63L; // '_'
456-
457-
String s = "Pjs$aJSZ05_";
458-
assertEquals(s, LongLib.toBase64(value));
459-
assertEquals(value, LongLib.longFromBase64(s));
460-
}
461-
462427
public static void testCompare() {
463428
doTestCompare(OP_COMPARE);
464429
}

0 commit comments

Comments
 (0)