Skip to content

Commit 579354f

Browse files
committed
Minor cleanup; release 1.4.4.3
This eliminates a seemingly-unnecessary step that wasted memory when decompressing URI-encoded text, and was putting one non-URI-safe char in URI-encoded text. It seems to encode and decode exactly the same.
1 parent 8f9f246 commit 579354f

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

src/main/java/blazing/chain/LZSEncoding.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
public final class LZSEncoding {
1717

18+
private LZSEncoding() {};
1819
private static final char[] keyStrBase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".toCharArray(),
1920
keyStrUriSafe = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$".toCharArray(),
2021
valStrBase64 = new char[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -32,7 +33,7 @@ public final class LZSEncoding {
3233
*/
3334
public static String compressToBase64(String uncompressed) {
3435
if (uncompressed == null)
35-
return "";
36+
return null;
3637
String res = _compress(uncompressed, 6, keyStrBase64, 0);
3738
switch (res.length() & 3) { // To produce valid Base64
3839
default: // When could this happen ?
@@ -58,8 +59,6 @@ public static String decompressFromBase64(String compressed) {
5859
if (compressed.isEmpty())
5960
return "";
6061
final char[] input = compressed.toCharArray();
61-
// function(index) { return getBaseValue(keyStrBase64,
62-
// input.charAt(index)); }
6362
return _decompress(input.length, 32, input, valStrBase64, 0);
6463
}
6564

@@ -98,7 +97,7 @@ public static String decompressFromUTF16(String compressed) {
9897
public static String compressToEncodedURIComponent(String uncompressed) {
9998
if (uncompressed == null)
10099
return null;
101-
return _compress(uncompressed, 6, keyStrUriSafe, 0) + ' ';
100+
return _compress(uncompressed, 6, keyStrUriSafe, 0) + '+';
102101
}
103102
/**
104103
* Decompresses a String that had been compressed with {@link #compressToEncodedURIComponent(String)}.
@@ -108,7 +107,6 @@ public static String compressToEncodedURIComponent(String uncompressed) {
108107
public static String decompressFromEncodedURIComponent(String compressed) {
109108
if (compressed == null) return null;
110109
if (compressed.isEmpty()) return "";
111-
compressed = compressed.replace(' ', '+');
112110
final char[] input = compressed.toCharArray();
113111
return _decompress(input.length, 32, input, valStrUriSafe, 0);
114112
}

src/main/java/blazing/chain/emu/blazing/chain/LZSEncoding.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
public final class LZSEncoding {
1313

14+
private LZSEncoding() {};
1415
private static final String keyStrBase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
1516
keyStrUriSafe = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$",
1617
valStrBase64 = new String(new char[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -28,7 +29,7 @@ public final class LZSEncoding {
2829
*/
2930
public static String compressToBase64(String uncompressed) {
3031
if (uncompressed == null)
31-
return "";
32+
return null;
3233
String res = _compress(uncompressed, 6, keyStrBase64, 0);
3334
switch (res.length() & 3) { // To produce valid Base64
3435
default: // When could this happen ?
@@ -92,7 +93,7 @@ public static String decompressFromUTF16(String compressed) {
9293
public static String compressToEncodedURIComponent(String uncompressed) {
9394
if (uncompressed == null)
9495
return null;
95-
return _compress(uncompressed, 6, keyStrUriSafe, 0) + ' ';
96+
return _compress(uncompressed, 6, keyStrUriSafe, 0) + '+';
9697
}
9798
/**
9899
* Decompresses a String that had been compressed with {@link #compressToEncodedURIComponent(String)}.
@@ -102,7 +103,6 @@ public static String compressToEncodedURIComponent(String uncompressed) {
102103
public static String decompressFromEncodedURIComponent(String compressed) {
103104
if (compressed == null) return null;
104105
if (compressed.isEmpty()) return "";
105-
compressed = compressed.replace(' ', '+');
106106
return _decompress(compressed.length(), 32, compressed, valStrUriSafe, 0);
107107
}
108108

0 commit comments

Comments
 (0)