diff --git a/pom.xml b/pom.xml index d6944f7..1dedfe6 100644 --- a/pom.xml +++ b/pom.xml @@ -141,11 +141,6 @@ - - org.apache.commons - commons-lang3 - 3.2 - org.springframework spring-context diff --git a/src/main/java/com/chrylis/codec/base58/Base58Codec.java b/src/main/java/com/chrylis/codec/base58/Base58Codec.java index f69a490..10b966e 100644 --- a/src/main/java/com/chrylis/codec/base58/Base58Codec.java +++ b/src/main/java/com/chrylis/codec/base58/Base58Codec.java @@ -3,11 +3,10 @@ import java.math.BigInteger; import java.nio.ByteBuffer; import java.nio.charset.Charset; +import java.util.Arrays; import java.util.Iterator; import java.util.NoSuchElementException; -import org.apache.commons.lang3.ArrayUtils; - /** * The operations contained in this class are confined to their methods and are entirely thread-safe. In fact, all of the methods * are implemented statically, and the instance-bound {@link #encode(byte[])} and {@link #decode(String)} methods are non-static @@ -40,7 +39,13 @@ public class Base58Codec { * {@code byte[]}. */ public static final char ALPHABET[] = "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ".toCharArray(); - + private static final int[] ALPHABET_INDEXES = new int[BLOCK_LENGTH_DIGITS]; + static { + Arrays.fill(ALPHABET_INDEXES, -1); + for (int i = 0; i < ALPHABET.length; i++) { + ALPHABET_INDEXES[ALPHABET[i]] = i; + } + } /** * Encode a stream of MSB-ordered bytes into Base58. Automatically pads negative numbers with a leading zero byte. * @@ -120,7 +125,7 @@ public static byte[] doDecode(final String source) { Iterator it = stringIterator(source); while (it.hasNext()) { - value = value.add(BigInteger.valueOf(ArrayUtils.indexOf(ALPHABET, it.next()))); + value = value.add(BigInteger.valueOf(ALPHABET_INDEXES[it.next()])); if (it.hasNext()) value = value.multiply(BASE); }