Coverage Report

Created: 2025-07-24 00:24

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