9
9
10
10
import static io .confluent .csid .utils .StringUtils .msg ;
11
11
import static io .confluent .parallelconsumer .OffsetEncoding .*;
12
- //import static io.confluent.parallelconsumer.OffsetEncoding.RunLengthCompressed;
13
12
14
13
class RunLengthEncoder extends OffsetEncoder {
15
14
16
15
// todo do these need to be atomic?
17
- private final AtomicInteger currentRunLengthCount ;
18
- private final AtomicBoolean previousRunLengthState ;
16
+ private int currentRunLengthCount = 0 ;
17
+ private boolean previousRunLengthState = false ;
19
18
20
19
private final List <Integer > runLengthEncodingIntegers ;
21
20
@@ -28,8 +27,6 @@ class RunLengthEncoder extends OffsetEncoder {
28
27
public RunLengthEncoder (OffsetSimultaneousEncoder offsetSimultaneousEncoder , Version newVersion ) {
29
28
super (offsetSimultaneousEncoder );
30
29
// run length setup
31
- currentRunLengthCount = new AtomicInteger ();
32
- previousRunLengthState = new AtomicBoolean (false );
33
30
runLengthEncodingIntegers = new ArrayList <>();
34
31
version = newVersion ;
35
32
}
@@ -62,7 +59,7 @@ public void encodeCompletedOffset(final int rangeIndex) {
62
59
63
60
@ Override
64
61
public byte [] serialise () throws EncodingNotSupportedException {
65
- runLengthEncodingIntegers .add (currentRunLengthCount . get () ); // add tail
62
+ runLengthEncodingIntegers .add (currentRunLengthCount ); // add tail
66
63
67
64
int entryWidth = switch (version ) {
68
65
case v1 -> Short .BYTES ;
@@ -81,7 +78,8 @@ public byte[] serialise() throws EncodingNotSupportedException {
81
78
case v2 -> {
82
79
runLengthEncodedByteBuffer .putInt (runlength );
83
80
}
84
- };
81
+ }
82
+ ;
85
83
}
86
84
87
85
byte [] array = runLengthEncodedByteBuffer .array ();
@@ -101,13 +99,13 @@ protected byte[] getEncodedBytes() {
101
99
102
100
private void encodeRunLength (final boolean currentIsComplete ) {
103
101
// run length
104
- boolean currentOffsetMatchesOurRunLengthState = previousRunLengthState . get () == currentIsComplete ;
102
+ boolean currentOffsetMatchesOurRunLengthState = previousRunLengthState == currentIsComplete ;
105
103
if (currentOffsetMatchesOurRunLengthState ) {
106
- currentRunLengthCount . getAndIncrement () ;
104
+ currentRunLengthCount ++ ;
107
105
} else {
108
- previousRunLengthState . set ( currentIsComplete ) ;
109
- runLengthEncodingIntegers .add (currentRunLengthCount . get () );
110
- currentRunLengthCount . set ( 1 ) ; // reset to 1
106
+ previousRunLengthState = currentIsComplete ;
107
+ runLengthEncodingIntegers .add (currentRunLengthCount );
108
+ currentRunLengthCount = 1 ; // reset to 1
111
109
}
112
110
}
113
111
}
0 commit comments