From 9f8a6c0cf916ff2601dbe8d67f93e3e01c879943 Mon Sep 17 00:00:00 2001 From: Frotty Date: Fri, 9 Jun 2017 17:54:12 +0200 Subject: [PATCH] cleanup some codebeat issues --- src/main/java/ru/eustas/zopfli/Deflate.java | 4 +- .../java/ru/eustas/zopfli/SymbolStats.java | 24 ++++------- .../crigges/jmpq3/compression/Huffman.java | 42 ++++++++----------- 3 files changed, 28 insertions(+), 42 deletions(-) diff --git a/src/main/java/ru/eustas/zopfli/Deflate.java b/src/main/java/ru/eustas/zopfli/Deflate.java index eab1f92..11c97bf 100644 --- a/src/main/java/ru/eustas/zopfli/Deflate.java +++ b/src/main/java/ru/eustas/zopfli/Deflate.java @@ -20,7 +20,7 @@ class Deflate { - static enum BlockType { + enum BlockType { DYNAMIC, FIXED } @@ -49,7 +49,7 @@ private static void getFixedTree(int[] llLengths, int[] dLengths) { } } - public static void greedy(Cookie cookie, LongestMatchCache lmc, byte[] input, int from, int to, LzStore store) { + static void greedy(Cookie cookie, LongestMatchCache lmc, byte[] input, int from, int to, LzStore store) { Hash h = cookie.h; h.init(input, Math.max(from - 0x8000, 0), from, to); int prevLength = 0; diff --git a/src/main/java/ru/eustas/zopfli/SymbolStats.java b/src/main/java/ru/eustas/zopfli/SymbolStats.java index 7c9434d..7dd9a2d 100644 --- a/src/main/java/ru/eustas/zopfli/SymbolStats.java +++ b/src/main/java/ru/eustas/zopfli/SymbolStats.java @@ -114,35 +114,30 @@ final void calculateDists() { } final void alloy(final SymbolStats ligand) { - int[] ligandLitLens = ligand.litLens; for (int i = 0; i < 288; i++) { - litLens[i] += ligandLitLens[i] / 2; + litLens[i] += ligand.litLens[i] / 2; } litLens[256] = 1; - int[] ligandDists = ligand.dists; for (int i = 0; i < 32; i++) { - dists[i] += ligandDists[i] / 2; + dists[i] += ligand.dists[i] / 2; } } final int randomizeFreqs(int z) { int[] data = litLens; int n = data.length; - for (int i = 0; i < n; i++) { - z = 0x7FFFFFFF & (1103515245 * z + 12345); - if ((z >>> 4) % 3 == 0) { - z = 0x7FFFFFFF & (1103515245 * z + 12345); - int p = z % n; - if (data[i] < data[p]) { - data[i] = data[p]; - } - } - } + z = getZ(z, data, n); data[256] = 1; data = dists; n = data.length; + z = getZ(z, data, n); + + return z; + } + + private int getZ(int z, int[] data, int n) { for (int i = 0; i < n; i++) { z = 0x7FFFFFFF & (1103515245 * z + 12345); if ((z >>> 4) % 3 == 0) { @@ -153,7 +148,6 @@ final int randomizeFreqs(int z) { } } } - return z; } diff --git a/src/main/java/systems/crigges/jmpq3/compression/Huffman.java b/src/main/java/systems/crigges/jmpq3/compression/Huffman.java index 035602d..4ae6dc7 100644 --- a/src/main/java/systems/crigges/jmpq3/compression/Huffman.java +++ b/src/main/java/systems/crigges/jmpq3/compression/Huffman.java @@ -1,20 +1,19 @@ package systems.crigges.jmpq3.compression; import java.nio.ByteBuffer; -import java.util.Arrays; import java.util.Map.Entry; import java.util.TreeMap; -public class Huffman { +class Huffman { private static class Node { - public Node parent; - public final Node[] child = new Node[2]; - public Node next; - public Node prev; - public int value; - public int probability; - - public void treeSwap(Node with) { + Node parent; + final Node[] child = new Node[2]; + Node next; + Node prev; + int value; + int probability; + + void treeSwap(Node with) { Node temp; if (parent == with.parent) { @@ -33,14 +32,14 @@ public void treeSwap(Node with) { with.parent = temp; } - public void insertAfter(Node where) { + void insertAfter(Node where) { prev = where; next = where.next; where.next = this; next.prev = this; } - public void listSwap(Node with) { + void listSwap(Node with) { if (next == with) { next = with.next; with.next = this; @@ -74,11 +73,11 @@ public void listSwap(Node with) { } } - public void newList() { + void newList() { prev = next = this; } - public Node removeFromList() { + Node removeFromList() { if (this == next) return null; prev.next = next; @@ -87,7 +86,7 @@ public Node removeFromList() { return next; } - public void joinList(Node list) { + void joinList(Node list) { Node tail = prev; prev = list.prev; @@ -98,13 +97,10 @@ public void joinList(Node list) { } } - private boolean adjustProbability; - private Node nodes = null; - private TreeMap sorted2 = new TreeMap(); + private TreeMap sorted2 = new TreeMap<>(); private Node root = null; - private Node[] valueToNode = new Node[0x102]; private int bitBuffer; private byte bitNumber; @@ -144,7 +140,6 @@ private void destroyTree(Node root) { else nodes.joinList(root); this.root = null; sorted2.clear(); - Arrays.fill(valueToNode, null); } private void insertNode(Node node) { @@ -156,7 +151,6 @@ private void insertNode(Node node) { current = test2.getValue(); node.insertAfter(current); } else { - current = root; if (root != null) { node.insertAfter(root.prev); } else { @@ -176,7 +170,6 @@ private Node addValueToTree(int value) { node.child[0] = null; node.child[1] = null; - valueToNode[value] = node; insertNode(node); // create branch node @@ -251,7 +244,6 @@ private void buildTree(byte tree) { node.child[1] = null; insertNode(node); - valueToNode[i] = node; } // generate tree @@ -276,12 +268,12 @@ private void buildTree(byte tree) { root.parent = null; } - public void Decompress(ByteBuffer in, ByteBuffer out) { + void Decompress(ByteBuffer in, ByteBuffer out) { setSource(in); byte type = (byte) getBits(8); buildTree(type); - adjustProbability = type == 0; + boolean adjustProbability = type == 0; for (; ; ) { Node current = root;