Skip to content

Commit a198abc

Browse files
committed
Use int as index to reduce cast operations
Decreases the number of instructions per block by almost 1
1 parent d4a37f6 commit a198abc

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

src/generic/json_structural_indexer.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,18 @@ class bit_indexer {
2222
// it helps tremendously.
2323
if (bits == 0)
2424
return;
25-
auto cnt = count_ones(bits);
25+
int cnt = static_cast<int>(count_ones(bits));
2626

2727
// Do the first 8 all together
28-
decltype(cnt) i;
29-
for (i=0; i<8; i++) {
28+
for (int i=0; i<8; i++) {
3029
this->tail[i] = idx + trailing_zeroes(bits);
3130
bits = clear_lowest_bit(bits);
3231
}
3332

3433
// Do the next 8 all together (we hope in most cases it won't happen at all
3534
// and the branch is easily predicted).
3635
if (unlikely(cnt > 8)) {
37-
for (i=8; i<16; i++) {
36+
for (int i=8; i<16; i++) {
3837
this->tail[i] = idx + trailing_zeroes(bits);
3938
bits = clear_lowest_bit(bits);
4039
}
@@ -43,7 +42,7 @@ class bit_indexer {
4342
// branch mispredictions here. 16+ structurals per block means either punctuation ({} [] , :)
4443
// or the start of a value ("abc" true 123) every four characters.
4544
if (unlikely(cnt > 16)) {
46-
i = 16;
45+
int i = 16;
4746
do {
4847
this->tail[i] = idx + trailing_zeroes(bits);
4948
bits = clear_lowest_bit(bits);

0 commit comments

Comments
 (0)