You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@johnzon.apache.org by st...@apache.org on 2026/08/14 08:16:16 UTC
(johnzon) 05/09: JOHNZON-435 remove old unused code
This is an automated email from the ASF dual-hosted git repository.
asf-gitbox-commits pushed a commit to branch johnzon-1.3.x
in repository https://gitbox.apache.org/repos/asf/johnzon.git
commit 9a9d5e808b53eeca1edb242d24651018421b45a9
Author: Mark Struberg <st...@apache.org>
AuthorDate: Thu Jul 23 20:32:30 2026 +0200
JOHNZON-435 remove old unused code
I benchmarked the old implementation and even wrote a new justWrite(char[]).
It performs worse than the (highly optimised native) Long.toString
---
.../org/apache/johnzon/core/JsonGeneratorImpl.java | 101 ---------------------
1 file changed, 101 deletions(-)
diff --git a/johnzon-core/src/main/java/org/apache/johnzon/core/JsonGeneratorImpl.java b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonGeneratorImpl.java
index c011b1f6..166021cb 100644
--- a/johnzon-core/src/main/java/org/apache/johnzon/core/JsonGeneratorImpl.java
+++ b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonGeneratorImpl.java
@@ -708,105 +708,4 @@ class JsonGeneratorImpl implements JsonGenerator, JsonChars, Serializable {
private void writeInt0(final int i) {
justWrite(String.valueOf(i));
}
-
- //optimized number optimizations
- /*
- private void writeLong0(final long i) {
- if (i == Long.MIN_VALUE) {
- justWrite("-9223372036854775808");
- return;
- }
- final int size = (i < 0) ? stringSize(-i) + 1 : stringSize(i);
- final char[] buf = new char[size];
- getChars(i, size, buf);
- justWrite(buf);
- }
-
- private void writeInt0(final int i) {
- if (i == Integer.MIN_VALUE) {
- justWrite("-2147483648");
- return;
- }
- final int size = (i < 0) ? stringSize(-i) + 1 : stringSize(i);
- final char[] buf = new char[size];
- getChars(i, size, buf);
- justWrite(buf);
- }
-
- private final static char[] DIGIT_TENS = { '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', '1', '1', '1', '1', '1', '1', '1',
- '1', '1', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '3', '3', '3', '3', '3', '3', '3', '3', '3', '3', '4', '4', '4',
- '4', '4', '4', '4', '4', '4', '4', '5', '5', '5', '5', '5', '5', '5', '5', '5', '5', '6', '6', '6', '6', '6', '6', '6', '6',
- '6', '6', '7', '7', '7', '7', '7', '7', '7', '7', '7', '7', '8', '8', '8', '8', '8', '8', '8', '8', '8', '8', '9', '9', '9',
- '9', '9', '9', '9', '9', '9', '9', };
-
- private final static char[] DIGIT_ONES = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7',
- '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2',
- '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7',
- '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2',
- '3', '4', '5', '6', '7', '8', '9', };
-
- private final static char[] DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
- 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
-
- // Requires positive x
- private static int stringSize(final long x) {
- long p = 10;
- for (int i = 1; i < 19; i++) {
- if (x < p) {
- return i;
- }
- p = 10 * p;
- }
- return 19;
- }
-
- private static void getChars(long i, final int index, final char[] buf) {
- long q;
- int r;
- int charPos = index;
- char sign = 0;
-
- if (i < 0) {
- sign = '-';
- i = -i;
- }
-
- // Get 2 digits/iteration using longs until quotient fits into an int
- while (i > Integer.MAX_VALUE) {
- q = i / 100;
- // really: r = i - (q * 100);
- r = (int) (i - ((q << 6) + (q << 5) + (q << 2)));
- i = q;
- buf[--charPos] = DIGIT_ONES[r];
- buf[--charPos] = DIGIT_TENS[r];
- }
-
- // Get 2 digits/iteration using ints
- int q2;
- int i2 = (int) i;
- while (i2 >= 65536) {
- q2 = i2 / 100;
- // really: r = i2 - (q * 100);
- r = i2 - ((q2 << 6) + (q2 << 5) + (q2 << 2));
- i2 = q2;
- buf[--charPos] = DIGIT_ONES[r];
- buf[--charPos] = DIGIT_TENS[r];
- }
-
- // Fall thru to fast mode for smaller numbers
- // assert(i2 <= 65536, i2);
- for (;;) {
- q2 = (i2 * 52429) >>> (16 + 3);
- r = i2 - ((q2 << 3) + (q2 << 1)); // r = i2-(q2*10) ...
- buf[--charPos] = DIGITS[r];
- i2 = q2;
- if (i2 == 0) {
- break;
- }
- }
- if (sign != 0) {
- buf[--charPos] = sign;
- }
- }
- */
}