Coverage Report

Created: 2026-07-27 20:25

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
1.23M
uint8_t* encode_varint32(uint8_t* dst, uint32_t v) {
14
    // Operate on characters as unsigneds
15
1.23M
    static const int B = 128;
16
1.23M
    if (v < (1 << 7)) {
17
1.15M
        *(dst++) = uint8_t(v);
18
1.15M
    } else if (v < (1 << 14)) {
19
39.5k
        *(dst++) = uint8_t(v | B);
20
39.5k
        *(dst++) = uint8_t(v >> 7);
21
39.5k
    } else if (v < (1 << 21)) {
22
37.1k
        *(dst++) = uint8_t(v | B);
23
37.1k
        *(dst++) = uint8_t((v >> 7) | B);
24
37.1k
        *(dst++) = uint8_t(v >> 14);
25
37.1k
    } else if (v < (1 << 28)) {
26
4
        *(dst++) = uint8_t(v | B);
27
4
        *(dst++) = uint8_t((v >> 7) | B);
28
4
        *(dst++) = uint8_t((v >> 14) | B);
29
4
        *(dst++) = uint8_t(v >> 21);
30
6
    } else {
31
6
        *(dst++) = uint8_t(v | B);
32
6
        *(dst++) = uint8_t((v >> 7) | B);
33
6
        *(dst++) = uint8_t((v >> 14) | B);
34
6
        *(dst++) = uint8_t((v >> 21) | B);
35
6
        *(dst++) = uint8_t(v >> 28);
36
6
    }
37
1.23M
    return dst;
38
1.23M
}
39
40
const uint8_t* decode_varint32_ptr_fallback(const uint8_t* p, const uint8_t* limit,
41
57.9k
                                            uint32_t* value) {
42
57.9k
    uint32_t result = 0;
43
149k
    for (uint32_t shift = 0; shift <= 28 && p < limit; shift += 7) {
44
149k
        uint32_t byte = *p;
45
149k
        p++;
46
149k
        if (byte & 128) {
47
            // More bytes are present
48
91.5k
            result |= ((byte & 127) << shift);
49
91.5k
        } else {
50
57.9k
            result |= (byte << shift);
51
57.9k
            *value = result;
52
57.9k
            return p;
53
57.9k
        }
54
149k
    }
55
2
    return nullptr;
56
57.9k
}
57
58
41.0k
const uint8_t* decode_varint64_ptr(const uint8_t* p, const uint8_t* limit, uint64_t* value) {
59
41.0k
    uint64_t result = 0;
60
156k
    for (uint32_t shift = 0; shift <= 63 && p < limit; shift += 7) {
61
156k
        uint64_t byte = *p;
62
156k
        p++;
63
156k
        if (byte & 128) {
64
            // More bytes are present
65
115k
            result |= ((byte & 127) << shift);
66
115k
        } else {
67
41.0k
            result |= (byte << shift);
68
41.0k
            *value = result;
69
41.0k
            return p;
70
41.0k
        }
71
156k
    }
72
2
    return nullptr;
73
41.0k
}
74
} // namespace doris