24
24
import java .util .Objects ;
25
25
import java .util .function .BiConsumer ;
26
26
import org .apache .logging .log4j .util .IndexedReadOnlyStringMap ;
27
- import org .apache .logging .log4j .util .Lazy ;
28
27
import org .apache .logging .log4j .util .StringBuilderFormattable ;
29
28
import org .apache .logging .log4j .util .StringMap ;
30
29
@@ -66,7 +65,9 @@ public final class JsonWriter implements AutoCloseable, Cloneable {
66
65
* character to use after backslash; and negative values, that generic
67
66
* (backslash - u) escaping is to be used.
68
67
*/
69
- private static final Lazy <int []> ESC_CODES = Lazy .pure (() -> {
68
+ private static final int [] ESC_CODES ;
69
+
70
+ static {
70
71
final int [] table = new int [128 ];
71
72
// Control chars need generic escape sequence
72
73
for (int i = 0 ; i < 32 ; ++i ) {
@@ -82,8 +83,8 @@ public final class JsonWriter implements AutoCloseable, Cloneable {
82
83
table [0x0C ] = 'f' ;
83
84
table [0x0A ] = 'n' ;
84
85
table [0x0D ] = 'r' ;
85
- return table ;
86
- });
86
+ ESC_CODES = table ;
87
+ }
87
88
88
89
private final char [] quoteBuffer ;
89
90
@@ -582,12 +583,11 @@ private void quoteString(final CharSequence seq, final int offset, final int len
582
583
length > 0 && Character .isHighSurrogate (seq .charAt (offset + length - 1 )) ? -1 : 0 ;
583
584
final int limit = offset + length + surrogateCorrection ;
584
585
int i = offset ;
585
- final int [] escCodes = ESC_CODES .get ();
586
586
outer :
587
587
while (i < limit ) {
588
588
while (true ) {
589
589
final char c = seq .charAt (i );
590
- if (c < escCodes .length && escCodes [c ] != 0 ) {
590
+ if (c < ESC_CODES .length && ESC_CODES [c ] != 0 ) {
591
591
break ;
592
592
}
593
593
stringBuilder .append (c );
@@ -596,7 +596,7 @@ private void quoteString(final CharSequence seq, final int offset, final int len
596
596
}
597
597
}
598
598
final char d = seq .charAt (i ++);
599
- final int escCode = escCodes [d ];
599
+ final int escCode = ESC_CODES [d ];
600
600
final int quoteBufferLength = escCode < 0 ? quoteNumeric (d ) : quoteNamed (escCode );
601
601
stringBuilder .append (quoteBuffer , 0 , quoteBufferLength );
602
602
}
@@ -646,12 +646,11 @@ private void quoteString(final char[] buffer, final int offset, final int length
646
646
final int surrogateCorrection = length > 0 && Character .isHighSurrogate (buffer [offset + length - 1 ]) ? -1 : 0 ;
647
647
final int limit = offset + length + surrogateCorrection ;
648
648
int i = offset ;
649
- final int [] escCodes = ESC_CODES .get ();
650
649
outer :
651
650
while (i < limit ) {
652
651
while (true ) {
653
652
final char c = buffer [i ];
654
- if (c < escCodes .length && escCodes [c ] != 0 ) {
653
+ if (c < ESC_CODES .length && ESC_CODES [c ] != 0 ) {
655
654
break ;
656
655
}
657
656
stringBuilder .append (c );
@@ -660,7 +659,7 @@ private void quoteString(final char[] buffer, final int offset, final int length
660
659
}
661
660
}
662
661
final char d = buffer [i ++];
663
- final int escCode = escCodes [d ];
662
+ final int escCode = ESC_CODES [d ];
664
663
final int quoteBufferLength = escCode < 0 ? quoteNumeric (d ) : quoteNamed (escCode );
665
664
stringBuilder .append (quoteBuffer , 0 , quoteBufferLength );
666
665
}
0 commit comments