Coverage Report

Created: 2026-07-02 12:30

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
57.0M
uint8_t* encode_varint32(uint8_t* dst, uint32_t v) {
14
    // Operate on characters as unsigneds
15
57.0M
    static const int B = 128;
16
57.0M
    if (v < (1 << 7)) {
17
55.8M
        *(dst++) = uint8_t(v);
18
55.8M
    } else if (v < (1 << 14)) {
19
1.15M
        *(dst++) = uint8_t(v | B);
20
1.15M
        *(dst++) = uint8_t(v >> 7);
21
1.15M
    } else if (v < (1 << 21)) {
22
43.9k
        *(dst++) = uint8_t(v | B);
23
43.9k
        *(dst++) = uint8_t((v >> 7) | B);
24
43.9k
        *(dst++) = uint8_t(v >> 14);
25
18.4E
    } else if (v < (1 << 28)) {
26
3
        *(dst++) = uint8_t(v | B);
27
3
        *(dst++) = uint8_t((v >> 7) | B);
28
3
        *(dst++) = uint8_t((v >> 14) | B);
29
3
        *(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
57.0M
    return dst;
38
57.0M
}
39
40
const uint8_t* decode_varint32_ptr_fallback(const uint8_t* p, const uint8_t* limit,
41
1.02M
                                            uint32_t* value) {
42
1.02M
    uint32_t result = 0;
43
2.21M
    for (uint32_t shift = 0; shift <= 28 && p < limit; shift += 7) {
44
2.21M
        uint32_t byte = *p;
45
2.21M
        p++;
46
2.21M
        if (byte & 128) {
47
            // More bytes are present
48
1.19M
            result |= ((byte & 127) << shift);
49
1.19M
        } else {
50
1.02M
            result |= (byte << shift);
51
1.02M
            *value = result;
52
1.02M
            return p;
53
1.02M
        }
54
2.21M
    }
55
1.03k
    return nullptr;
56
1.02M
}
57
58
327k
const uint8_t* decode_varint64_ptr(const uint8_t* p, const uint8_t* limit, uint64_t* value) {
59
327k
    uint64_t result = 0;
60
1.14M
    for (uint32_t shift = 0; shift <= 63 && p < limit; shift += 7) {
61
1.14M
        uint64_t byte = *p;
62
1.14M
        p++;
63
1.14M
        if (byte & 128) {
64
            // More bytes are present
65
818k
            result |= ((byte & 127) << shift);
66
818k
        } else {
67
327k
            result |= (byte << shift);
68
327k
            *value = result;
69
327k
            return p;
70
327k
        }
71
1.14M
    }
72
18.4E
    return nullptr;
73
327k
}
74
} // namespace doris