/src/re2/re2/bitmap256.cc
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright 2023 The RE2 Authors. All Rights Reserved. |
2 | | // Use of this source code is governed by a BSD-style |
3 | | // license that can be found in the LICENSE file. |
4 | | |
5 | | #include "re2/bitmap256.h" |
6 | | |
7 | | #include <stdint.h> |
8 | | |
9 | | #include "util/util.h" |
10 | | #include "util/logging.h" |
11 | | |
12 | | namespace re2 { |
13 | | |
14 | 7.87G | int Bitmap256::FindNextSetBit(int c) const { |
15 | 7.87G | DCHECK_GE(c, 0); |
16 | 7.87G | DCHECK_LE(c, 255); |
17 | | |
18 | | // Check the word that contains the bit. Mask out any lower bits. |
19 | 7.87G | int i = c / 64; |
20 | 7.87G | uint64_t word = words_[i] & (~uint64_t{0} << (c % 64)); |
21 | 7.87G | if (word != 0) |
22 | 7.24G | return (i * 64) + FindLSBSet(word); |
23 | | |
24 | | // Check any following words. |
25 | 632M | i++; |
26 | 632M | switch (i) { |
27 | 63.4M | case 1: |
28 | 63.4M | if (words_[1] != 0) |
29 | 9.31M | return (1 * 64) + FindLSBSet(words_[1]); |
30 | 63.4M | FALLTHROUGH_INTENDED; |
31 | 131M | case 2: |
32 | 131M | if (words_[2] != 0) |
33 | 1.03M | return (2 * 64) + FindLSBSet(words_[2]); |
34 | 131M | FALLTHROUGH_INTENDED; |
35 | 621M | case 3: |
36 | 621M | if (words_[3] != 0) |
37 | 621M | return (3 * 64) + FindLSBSet(words_[3]); |
38 | 621M | FALLTHROUGH_INTENDED; |
39 | 0 | default: |
40 | 0 | return -1; |
41 | 632M | } |
42 | 632M | } |
43 | | |
44 | | } // namespace re2 |