Coverage Report

Created: 2026-01-08 03:46

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
35.0M
uint8_t* encode_varint32(uint8_t* dst, uint32_t v) {
15
    // Operate on characters as unsigneds
16
35.0M
    static const int B = 128;
17
35.0M
    if (v < (1 << 7)) {
18
33.6M
        *(dst++) = uint8_t(v);
19
33.6M
    } else if (v < (1 << 14)) {
20
1.37M
        *(dst++) = uint8_t(v | B);
21
1.37M
        *(dst++) = uint8_t(v >> 7);
22
1.37M
    } else if (v < (1 << 21)) {
23
43.2k
        *(dst++) = uint8_t(v | B);
24
43.2k
        *(dst++) = uint8_t((v >> 7) | B);
25
43.2k
        *(dst++) = uint8_t(v >> 14);
26
18.4E
    } else if (v < (1 << 28)) {
27
2
        *(dst++) = uint8_t(v | B);
28
2
        *(dst++) = uint8_t((v >> 7) | B);
29
2
        *(dst++) = uint8_t((v >> 14) | B);
30
2
        *(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
35.0M
    return dst;
39
35.0M
}
40
41
const uint8_t* decode_varint32_ptr_fallback(const uint8_t* p, const uint8_t* limit,
42
5.87M
                                            uint32_t* value) {
43
5.87M
    uint32_t result = 0;
44
12.0M
    for (uint32_t shift = 0; shift <= 28 && p < limit; shift += 7) {
45
12.0M
        uint32_t byte = *p;
46
12.0M
        p++;
47
12.0M
        if (byte & 128) {
48
            // More bytes are present
49
6.14M
            result |= ((byte & 127) << shift);
50
6.14M
        } else {
51
5.86M
            result |= (byte << shift);
52
5.86M
            *value = result;
53
5.86M
            return p;
54
5.86M
        }
55
12.0M
    }
56
11.4k
    return nullptr;
57
5.87M
}
58
59
2.30M
const uint8_t* decode_varint64_ptr(const uint8_t* p, const uint8_t* limit, uint64_t* value) {
60
2.30M
    uint64_t result = 0;
61
8.66M
    for (uint32_t shift = 0; shift <= 63 && p < limit; shift += 7) {
62
8.66M
        uint64_t byte = *p;
63
8.66M
        p++;
64
8.66M
        if (byte & 128) {
65
            // More bytes are present
66
6.35M
            result |= ((byte & 127) << shift);
67
6.35M
        } else {
68
2.30M
            result |= (byte << shift);
69
2.30M
            *value = result;
70
2.30M
            return p;
71
2.30M
        }
72
8.66M
    }
73
1
    return nullptr;
74
2.30M
}
75
#include "common/compile_check_end.h"
76
} // namespace doris