From 1788c0b75589fe2a975c094cc5f5cede153e4795 Mon Sep 17 00:00:00 2001 From: Goktug Gokdogan Date: Thu, 27 Aug 2015 18:29:56 -0700 Subject: [PATCH] Removes base64 encoding code from LongLib. The code was only used from GWT-RPC client-side and already copied there. Change-Id: I1451678542580395fa3fcc199472cbaed72ef9a8 --- .../super/com/google/gwt/lang/LongLib.java | 86 ------------------- .../test/com/google/gwt/lang/LongLibTest.java | 35 -------- 2 files changed, 121 deletions(-) diff --git a/dev/core/super/com/google/gwt/lang/LongLib.java b/dev/core/super/com/google/gwt/lang/LongLib.java index 095419f9e29..08a9699d16e 100644 --- a/dev/core/super/com/google/gwt/lang/LongLib.java +++ b/dev/core/super/com/google/gwt/lang/LongLib.java @@ -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); } @@ -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)); @@ -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. */ diff --git a/dev/core/test/com/google/gwt/lang/LongLibTest.java b/dev/core/test/com/google/gwt/lang/LongLibTest.java index 7249fe5a35d..ed982b4d3eb 100644 --- a/dev/core/test/com/google/gwt/lang/LongLibTest.java +++ b/dev/core/test/com/google/gwt/lang/LongLibTest.java @@ -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); }