You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2026/04/04 21:51:45 UTC
(commons-codec) 03/04: Make Base58 stateless
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-codec.git
commit 7d3deb80bcb40278c516e05f63badec9d6d7d0a2
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Apr 4 17:49:56 2026 -0400
Make Base58 stateless
The original PR code didn't understand how to use a Context.
---
.../java/org/apache/commons/codec/binary/Base58.java | 18 ++++++------------
1 file changed, 6 insertions(+), 12 deletions(-)
diff --git a/src/main/java/org/apache/commons/codec/binary/Base58.java b/src/main/java/org/apache/commons/codec/binary/Base58.java
index 7be3575b..47d8a749 100644
--- a/src/main/java/org/apache/commons/codec/binary/Base58.java
+++ b/src/main/java/org/apache/commons/codec/binary/Base58.java
@@ -19,8 +19,6 @@ package org.apache.commons.codec.binary;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
-import java.util.Map;
-import java.util.WeakHashMap;
/**
* Provides Base58 encoding and decoding as commonly used in cryptocurrency and blockchain applications.
@@ -138,8 +136,6 @@ public class Base58 extends BaseNCodec {
return new Builder();
}
- private final transient Map<Context, byte[]> accumulated = new WeakHashMap<>();
-
/**
* Constructs a Base58 codec used for encoding and decoding.
*/
@@ -238,20 +234,19 @@ public class Base58 extends BaseNCodec {
}
if (length < 0) {
context.eof = true;
- final byte[] accumulate = accumulated.getOrDefault(context, EMPTY);
+ final byte[] accumulate = context.buffer = context.buffer != null ? context.buffer : EMPTY;
if (accumulate.length > 0) {
convertFromBase58(accumulate, context);
}
- accumulated.remove(context);
return;
}
- final byte[] accumulate = accumulated.getOrDefault(context, EMPTY);
+ final byte[] accumulate = context.buffer = context.buffer != null ? context.buffer : EMPTY;
final byte[] newAccumulated = new byte[accumulate.length + length];
if (accumulate.length > 0) {
System.arraycopy(accumulate, 0, newAccumulated, 0, accumulate.length);
}
System.arraycopy(array, offset, newAccumulated, accumulate.length, length);
- accumulated.put(context, newAccumulated);
+ context.buffer = newAccumulated;
}
/**
@@ -272,18 +267,17 @@ public class Base58 extends BaseNCodec {
}
if (length < 0) {
context.eof = true;
- final byte[] accumulate = accumulated.getOrDefault(context, EMPTY);
+ final byte[] accumulate = context.buffer = context.buffer != null ? context.buffer : EMPTY;
convertToBase58(accumulate, context);
- accumulated.remove(context);
return;
}
- final byte[] accumulate = accumulated.getOrDefault(context, EMPTY);
+ final byte[] accumulate = context.buffer = context.buffer != null ? context.buffer : EMPTY;
final byte[] newAccumulated = new byte[accumulate.length + length];
if (accumulate.length > 0) {
System.arraycopy(accumulate, 0, newAccumulated, 0, accumulate.length);
}
System.arraycopy(array, offset, newAccumulated, accumulate.length, length);
- accumulated.put(context, newAccumulated);
+ context.buffer = newAccumulated;
}
/**