Coverage Report

Created: 2026-04-13 10:38

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/util/coding.cpp
Line
Count
Source
1
//  Copyright (c) 2011-present, Facebook, Inc.  All rights reserved.
2
//  This source code is licensed under both the GPLv2 (found in the
3
//  COPYING file in the root directory) and Apache 2.0 License
4
//  (found in the LICENSE.Apache file in the root directory).
5
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
6
// Use of this source code is governed by a BSD-style license that can be
7
// found in the LICENSE file. See the AUTHORS file for names of contributors.
8
9
#include "util/coding.h"
10
11
namespace doris {
12
13
42.6M
uint8_t* encode_varint32(uint8_t* dst, uint32_t v) {
14
    // Operate on characters as unsigneds
15
42.6M
    static const int B = 128;
16
42.6M
    if (v < (1 << 7)) {
17
42.0M
        *(dst++) = uint8_t(v);
18
42.0M
    } else if (v < (1 << 14)) {
19
650k
        *(dst++) = uint8_t(v | B);
20
650k
        *(dst++) = uint8_t(v >> 7);
21
18.4E
    } else if (v < (1 << 21)) {
22
43.3k
        *(dst++) = uint8_t(v | B);
23
43.3k
        *(dst++) = uint8_t((v >> 7) | B);
24
43.3k
        *(dst++) = uint8_t(v >> 14);
25
18.4E
    } else if (v < (1 << 28)) {
26
2
        *(dst++) = uint8_t(v | B);
27
2
        *(dst++) = uint8_t((v >> 7) | B);
28
2
        *(dst++) = uint8_t((v >> 14) | B);
29
2
        *(dst++) = uint8_t(v >> 21);
30
18.4E
    } else {
31
18.4E
        *(dst++) = uint8_t(v | B);
32
18.4E
        *(dst++) = uint8_t((v >> 7) | B);
33
18.4E
        *(dst++) = uint8_t((v >> 14) | B);
34
18.4E
        *(dst++) = uint8_t((v >> 21) | B);
35
18.4E
        *(dst++) = uint8_t(v >> 28);
36
18.4E
    }
37
42.6M
    return dst;
38
42.6M
}
39
40
const uint8_t* decode_varint32_ptr_fallback(const uint8_t* p, const uint8_t* limit,
41
5.42M
                                            uint32_t* value) {
42
5.42M
    uint32_t result = 0;
43
11.2M
    for (uint32_t shift = 0; shift <= 28 && p < limit; shift += 7) {
44
11.2M
        uint32_t byte = *p;
45
11.2M
        p++;
46
11.2M
        if (byte & 128) {
47
            // More bytes are present
48
5.81M
            result |= ((byte & 127) << shift);
49
5.81M
        } else {
50
5.40M
            result |= (byte << shift);
51
5.40M
            *value = result;
52
5.40M
            return p;
53
5.40M
        }
54
11.2M
    }
55
16.9k
    return nullptr;
56
5.42M
}
57
58
3.65M
const uint8_t* decode_varint64_ptr(const uint8_t* p, const uint8_t* limit, uint64_t* value) {
59
3.65M
    uint64_t result = 0;
60
11.8M
    for (uint32_t shift = 0; shift <= 63 && p < limit; shift += 7) {
61
11.8M
        uint64_t byte = *p;
62
11.8M
        p++;
63
11.8M
        if (byte & 128) {
64
            // More bytes are present
65
8.18M
            result |= ((byte & 127) << shift);
66
8.18M
        } else {
67
3.65M
            result |= (byte << shift);
68
3.65M
            *value = result;
69
3.65M
            return p;
70
3.65M
        }
71
11.8M
    }
72
18.4E
    return nullptr;
73
3.65M
}
74
} // namespace doris