Skip to content

Commit

Permalink
Some tiny optimization on LZBDecompression.
Browse files Browse the repository at this point in the history
This also gets LZBTest working again!
  • Loading branch information
tommyettinger committed Jan 31, 2025
1 parent 5ddd646 commit acd36ec
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ public static String decompressFromBytes(byte[] compressedBytes, int offset, int
position = resetValue;
val = compressedBytes[index++];
}
bits |= (resb != 0 ? 1 : 0) << power++;
bits |= (resb != 0 ? 1 << power : 0);
power++;
}

switch (bits) {
Expand All @@ -101,7 +102,8 @@ public static String decompressFromBytes(byte[] compressedBytes, int offset, int
position = resetValue;
val = compressedBytes[index++];
}
bits |= (resb != 0 ? 1 : 0) << power++;
bits |= (resb != 0 ? 1 << power : 0);
power++;
}
c = String.valueOf(bits);
break;
Expand All @@ -116,7 +118,8 @@ public static String decompressFromBytes(byte[] compressedBytes, int offset, int
position = resetValue;
val = compressedBytes[index++];
}
bits |= (resb != 0 ? 1 : 0) << power++;
bits |= (resb != 0 ? 1 << power : 0);
power++;
}
c = String.valueOf(bits);
break;
Expand All @@ -140,7 +143,8 @@ public static String decompressFromBytes(byte[] compressedBytes, int offset, int
position = resetValue;
val = compressedBytes[index++];
}
cc |= (resb != 0 ? 1 : 0) << power++;
cc |= (resb != 0 ? 1 << power : 0);
power++;
}
switch (cc) {
case 0:
Expand All @@ -154,7 +158,8 @@ public static String decompressFromBytes(byte[] compressedBytes, int offset, int
position = resetValue;
val = compressedBytes[index++];
}
bits |= (resb != 0 ? 1 : 0) << power++;
bits |= (resb != 0 ? 1 << power : 0);
power++;
}

dictionary.add(String.valueOf(bits));
Expand All @@ -172,7 +177,8 @@ public static String decompressFromBytes(byte[] compressedBytes, int offset, int
position = resetValue;
val = compressedBytes[index++];
}
bits |= (resb != 0 ? 1 : 0) << power++;
bits |= (resb != 0 ? 1 << power : 0);
power++;
}
dictionary.add(String.valueOf(bits));
cc = dictSize++;
Expand Down
14 changes: 7 additions & 7 deletions src/test/java/com/github/tommyettinger/textra/LZBTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import com.github.tommyettinger.textra.utils.LZBCompression;

/**
* Doesn't currently run because the assets were removed. They were large.
* Tests binary LZ (String) compression, both to and from.
*/
public class LZBTest extends ApplicationAdapter {
Stage stage;
Expand All @@ -43,8 +43,8 @@ public class LZBTest extends ApplicationAdapter {
String compressedText = "";
@Override
public void create() {
FileHandle uncompressedFile = Gdx.files.local("knownFonts/fontwriter/DejaVu-Sans-Condensed-sdf.json");
FileHandle compressedFile = Gdx.files.local("knownFonts/fontwriter/DejaVu-Sans-Condensed-sdf.dat");
FileHandle uncompressedFile = Gdx.files.local("src/test/resources/experimental/Gentium-standard.json");
FileHandle compressedFile = Gdx.files.local("src/test/resources/experimental/Gentium-standard.dat");
if(!compressedFile.exists()){
ByteArray ba = LZBCompression.compressToByteArray(uncompressedFile.readString("UTF-8"));
compressedFile.writeBytes(ba.items, 0, ba.size, false);
Expand All @@ -58,9 +58,9 @@ public void create() {
uncompressedButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
uncompressedStartTime = System.currentTimeMillis();
uncompressedStartTime = System.nanoTime();
uncompressedText = uncompressedFile.readString("UTF-8");
String script = (System.currentTimeMillis() - uncompressedStartTime) + " ms";
String script = (System.nanoTime() - uncompressedStartTime) + " ns";
System.out.println(script);
uncompressedTime.setText(script);
uncompressedTime.layout();
Expand All @@ -71,9 +71,9 @@ public void clicked(InputEvent event, float x, float y) {
compressedButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
compressedStartTime = System.currentTimeMillis();
compressedStartTime = System.nanoTime();
compressedText = compressedFile.readString("UTF-8");
String script = (System.currentTimeMillis() - compressedStartTime) + " ms";
String script = (System.nanoTime() - compressedStartTime) + " ns";
System.out.println(script);
compressedTime.setText(script);
compressedTime.layout();
Expand Down
Binary file not shown.

0 comments on commit acd36ec

Please sign in to comment.