Coverage Report

Created: 2025-09-30 11:14

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
432k
uint8_t* encode_varint32(uint8_t* dst, uint32_t v) {
15
    // Operate on characters as unsigneds
16
432k
    static const int B = 128;
17
432k
    if (v < (1 << 7)) {
18
390k
        *(dst++) = uint8_t(v);
19
390k
    } else if (v < (1 << 14)) {
20
23.5k
        *(dst++) = uint8_t(v | B);
21
23.5k
        *(dst++) = uint8_t(v >> 7);
22
23.5k
    } else if (v < (1 << 21)) {
23
18.5k
        *(dst++) = uint8_t(v | B);
24
18.5k
        *(dst++) = uint8_t((v >> 7) | B);
25
18.5k
        *(dst++) = uint8_t(v >> 14);
26
18.5k
    } 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
2
    } else {
32
2
        *(dst++) = uint8_t(v | B);
33
2
        *(dst++) = uint8_t((v >> 7) | B);
34
2
        *(dst++) = uint8_t((v >> 14) | B);
35
2
        *(dst++) = uint8_t((v >> 21) | B);
36
2
        *(dst++) = uint8_t(v >> 28);
37
2
    }
38
432k
    return dst;
39
432k
}
40
41
const uint8_t* decode_varint32_ptr_fallback(const uint8_t* p, const uint8_t* limit,
42
29.0k
                                            uint32_t* value) {
43
29.0k
    uint32_t result = 0;
44
74.8k
    for (uint32_t shift = 0; shift <= 28 && p < limit; shift += 7) {
45
74.8k
        uint32_t byte = *p;
46
74.8k
        p++;
47
74.8k
        if (byte & 128) {
48
            // More bytes are present
49
45.8k
            result |= ((byte & 127) << shift);
50
45.8k
        } else {
51
29.0k
            result |= (byte << shift);
52
29.0k
            *value = result;
53
29.0k
            return p;
54
29.0k
        }
55
74.8k
    }
56
1
    return nullptr;
57
29.0k
}
58
59
20.5k
const uint8_t* decode_varint64_ptr(const uint8_t* p, const uint8_t* limit, uint64_t* value) {
60
20.5k
    uint64_t result = 0;
61
78.5k
    for (uint32_t shift = 0; shift <= 63 && p < limit; shift += 7) {
62
78.5k
        uint64_t byte = *p;
63
78.5k
        p++;
64
78.5k
        if (byte & 128) {
65
            // More bytes are present
66
57.9k
            result |= ((byte & 127) << shift);
67
57.9k
        } else {
68
20.5k
            result |= (byte << shift);
69
20.5k
            *value = result;
70
20.5k
            return p;
71
20.5k
        }
72
78.5k
    }
73
1
    return nullptr;
74
20.5k
}
75
#include "common/compile_check_end.h"
76
} // namespace doris