6
6
class CharactersClassifier {
7
7
8
8
private static final byte LOW_NIBBLE_MASK = 0x0f ;
9
- private static final ByteVector WHITESPACE_TABLE = ByteVector .fromArray (
10
- ByteVector .SPECIES_256 ,
11
- new byte []{
12
- ' ' , 100 , 100 , 100 , 17 , 100 , 113 , 2 , 100 , '\t' , '\n' , 112 , 100 , '\r' , 100 , 100 ,
13
- ' ' , 100 , 100 , 100 , 17 , 100 , 113 , 2 , 100 , '\t' , '\n' , 112 , 100 , '\r' , 100 , 100
14
- },
15
- 0
16
- );
17
- private static final ByteVector OP_TABLE = ByteVector .fromArray (
18
- ByteVector .SPECIES_256 ,
19
- new byte []{
20
- 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , ':' , '{' , ',' , '}' , 0 , 0 ,
21
- 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , ':' , '{' , ',' , '}' , 0 , 0
22
- },
23
- 0
24
- );
9
+
10
+ private static final ByteVector WHITESPACE_TABLE =
11
+ ByteVector .fromArray (
12
+ StructuralIndexer .SPECIES ,
13
+ repeat (new byte []{' ' , 100 , 100 , 100 , 17 , 100 , 113 , 2 , 100 , '\t' , '\n' , 112 , 100 , '\r' , 100 , 100 }, StructuralIndexer .SPECIES .vectorByteSize () / 4 ),
14
+ 0 );
15
+
16
+ private static final ByteVector OP_TABLE =
17
+ ByteVector .fromArray (
18
+ StructuralIndexer .SPECIES ,
19
+ repeat (new byte []{0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , ':' , '{' , ',' , '}' , 0 , 0 }, StructuralIndexer .SPECIES .vectorByteSize () / 4 ),
20
+ 0 );
21
+
22
+ private static byte [] repeat (byte [] array , int n ) {
23
+ byte [] result = new byte [n * array .length ];
24
+ for (int dst = 0 ; dst < result .length ; dst += array .length ) {
25
+ System .arraycopy (array , 0 , result , dst , array .length );
26
+ }
27
+ return result ;
28
+ }
29
+
30
+ JsonCharacterBlock classify (ByteVector chunk0 ) {
31
+ VectorShuffle <Byte > chunk0Low = extractLowNibble (chunk0 ).toShuffle ();
32
+ long whitespace = eq (chunk0 , WHITESPACE_TABLE .rearrange (chunk0Low ));
33
+ ByteVector curlified0 = curlify (chunk0 );
34
+ long op = eq (curlified0 , OP_TABLE .rearrange (chunk0Low ));
35
+ return new JsonCharacterBlock (whitespace , op );
36
+ }
25
37
26
38
JsonCharacterBlock classify (ByteVector chunk0 , ByteVector chunk1 ) {
27
39
VectorShuffle <Byte > chunk0Low = extractLowNibble (chunk0 ).toShuffle ();
28
40
VectorShuffle <Byte > chunk1Low = extractLowNibble (chunk1 ).toShuffle ();
29
-
30
- long whitespace = eq (
31
- chunk0 ,
32
- WHITESPACE_TABLE .rearrange (chunk0Low ),
33
- chunk1 ,
34
- WHITESPACE_TABLE .rearrange (chunk1Low )
35
- );
36
-
41
+ long whitespace = eq (chunk0 , WHITESPACE_TABLE .rearrange (chunk0Low ), chunk1 , WHITESPACE_TABLE .rearrange (chunk1Low ));
37
42
ByteVector curlified0 = curlify (chunk0 );
38
43
ByteVector curlified1 = curlify (chunk1 );
39
- long op = eq (
40
- curlified0 ,
41
- OP_TABLE .rearrange (chunk0Low ),
42
- curlified1 ,
43
- OP_TABLE .rearrange (chunk1Low )
44
- );
45
-
44
+ long op = eq (curlified0 , OP_TABLE .rearrange (chunk0Low ), curlified1 , OP_TABLE .rearrange (chunk1Low ));
46
45
return new JsonCharacterBlock (whitespace , op );
47
46
}
48
47
@@ -55,9 +54,13 @@ private ByteVector curlify(ByteVector vector) {
55
54
return vector .or ((byte ) 0x20 );
56
55
}
57
56
57
+ private long eq (ByteVector chunk0 , ByteVector mask0 ) {
58
+ return chunk0 .eq (mask0 ).toLong ();
59
+ }
60
+
58
61
private long eq (ByteVector chunk0 , ByteVector mask0 , ByteVector chunk1 , ByteVector mask1 ) {
59
- long rLo = chunk0 .eq (mask0 ).toLong ();
60
- long rHi = chunk1 .eq (mask1 ).toLong ();
61
- return rLo | (rHi << 32 );
62
- }
62
+ long r0 = chunk0 .eq (mask0 ).toLong ();
63
+ long r1 = chunk1 .eq (mask1 ).toLong ();
64
+ return r0 | (r1 << 32 );
65
+ }
63
66
}
0 commit comments