Coverage Report

Created: 2026-01-13 02:48

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
#include "common/compile_check_begin.h"
13
14
42.7M
uint8_t* encode_varint32(uint8_t* dst, uint32_t v) {
15
    // Operate on characters as unsigneds
16
42.7M
    static const int B = 128;
17
42.7M
    if (v < (1 << 7)) {
18
41.4M
        *(dst++) = uint8_t(v);
19
41.4M
    } else if (v < (1 << 14)) {
20
1.30M
        *(dst++) = uint8_t(v | B);
21
1.30M
        *(dst++) = uint8_t(v >> 7);
22
1.30M
    } else if (v < (1 << 21)) {
23
52.5k
        *(dst++) = uint8_t(v | B);
24
52.5k
        *(dst++) = uint8_t((v >> 7) | B);
25
52.5k
        *(dst++) = uint8_t(v >> 14);
26
18.4E
    } else if (v < (1 << 28)) {
27
0
        *(dst++) = uint8_t(v | B);
28
0
        *(dst++) = uint8_t((v >> 7) | B);
29
0
        *(dst++) = uint8_t((v >> 14) | B);
30
0
        *(dst++) = uint8_t(v >> 21);
31
18.4E
    } else {
32
18.4E
        *(dst++) = uint8_t(v | B);
33
18.4E
        *(dst++) = uint8_t((v >> 7) | B);
34
18.4E
        *(dst++) = uint8_t((v >> 14) | B);
35
18.4E
        *(dst++) = uint8_t((v >> 21) | B);
36
18.4E
        *(dst++) = uint8_t(v >> 28);
37
18.4E
    }
38
42.7M
    return dst;
39
42.7M
}
40
41
const uint8_t* decode_varint32_ptr_fallback(const uint8_t* p, const uint8_t* limit,
42
4.83M
                                            uint32_t* value) {
43
4.83M
    uint32_t result = 0;
44
10.0M
    for (uint32_t shift = 0; shift <= 28 && p < limit; shift += 7) {
45
10.0M
        uint32_t byte = *p;
46
10.0M
        p++;
47
10.0M
        if (byte & 128) {
48
            // More bytes are present
49
5.20M
            result |= ((byte & 127) << shift);
50
5.20M
        } else {
51
4.83M
            result |= (byte << shift);
52
4.83M
            *value = result;
53
4.83M
            return p;
54
4.83M
        }
55
10.0M
    }
56
6.10k
    return nullptr;
57
4.83M
}
58
59
3.53M
const uint8_t* decode_varint64_ptr(const uint8_t* p, const uint8_t* limit, uint64_t* value) {
60
3.53M
    uint64_t result = 0;
61
11.7M
    for (uint32_t shift = 0; shift <= 63 && p < limit; shift += 7) {
62
11.7M
        uint64_t byte = *p;
63
11.7M
        p++;
64
11.7M
        if (byte & 128) {
65
            // More bytes are present
66
8.21M
            result |= ((byte & 127) << shift);
67
8.21M
        } else {
68
3.52M
            result |= (byte << shift);
69
3.52M
            *value = result;
70
3.52M
            return p;
71
3.52M
        }
72
11.7M
    }
73
5.01k
    return nullptr;
74
3.53M
}
75
#include "common/compile_check_end.h"
76
} // namespace doris