• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tstack / lnav / 23687151512-2894

28 Mar 2026 02:20PM UTC coverage: 69.042% (-0.02%) from 69.061%
23687151512-2894

push

github

tstack
[tidy] move src file/line into logline_values_vector

83 of 114 new or added lines in 11 files covered. (72.81%)

12 existing lines in 4 files now uncovered.

53022 of 76797 relevant lines covered (69.04%)

533147.5 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.0
/src/shared_buffer.hh
1
/**
2
 * Copyright (c) 2014, Timothy Stack
3
 *
4
 * All rights reserved.
5
 *
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions are met:
8
 *
9
 * * Redistributions of source code must retain the above copyright notice, this
10
 * list of conditions and the following disclaimer.
11
 * * Redistributions in binary form must reproduce the above copyright notice,
12
 * this list of conditions and the following disclaimer in the documentation
13
 * and/or other materials provided with the distribution.
14
 * * Neither the name of Timothy Stack nor the names of its contributors
15
 * may be used to endorse or promote products derived from this software
16
 * without specific prior written permission.
17
 *
18
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ''AS IS'' AND ANY
19
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
22
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
 *
29
 * @file shared_buffer.hh
30
 */
31

32
#ifndef shared_buffer_hh
33
#define shared_buffer_hh
34

35
#include <string>
36
#include <string_view>
37
#include <vector>
38

39
#include <string.h>
40
#include <sys/types.h>
41

42
#include "base/auto_mem.hh"
43
#include "base/file_range.hh"
44
#include "base/intern_string.hh"
45
#include "base/line_range.hh"
46
#include "base/lnav_log.hh"
47

48
class shared_buffer;
49

50
#define SHARED_BUFFER_TRACE 0
51

52
struct shared_buffer_ref {
53
    shared_buffer_ref(const char* data = nullptr, size_t len = 0)
175,315✔
54
        : sb_owner(nullptr), sb_data(data), sb_length(len)
175,315✔
55
    {
56
    }
175,315✔
57

58
    ~shared_buffer_ref() { this->disown(); }
694,453✔
59

60
    shared_buffer_ref(const shared_buffer_ref& other) = delete;
61

62
    shared_buffer_ref(shared_buffer_ref&& other) noexcept;
63

64
    shared_buffer_ref& operator=(const shared_buffer_ref& other) = delete;
65

66
    shared_buffer_ref clone() const
8,604✔
67
    {
68
        shared_buffer_ref retval;
8,604✔
69

70
        retval.copy_ref(*this);
8,604✔
71

72
        return retval;
8,604✔
73
    }
×
74

75
    shared_buffer_ref& operator=(shared_buffer_ref&& other) noexcept;
76

77
    bool empty() const
11,155✔
78
    {
79
        return this->sb_data == nullptr || this->sb_length == 0;
11,155✔
80
    }
81

82
    const char* get_data() const { return this->sb_data; }
1,139,486✔
83

84
    const char* get_data_at(off_t offset) const
313,984✔
85
    {
86
        return &this->sb_data[offset];
313,984✔
87
    }
88

89
    size_t length() const { return this->sb_length; }
1,026,976✔
90

91
    shared_buffer_ref& rtrim(bool pred(char))
47,482✔
92
    {
93
        while (this->sb_length > 0 && pred(this->sb_data[this->sb_length - 1]))
67,221✔
94
        {
95
            this->sb_length -= 1;
19,739✔
96
        }
97

98
        return *this;
47,482✔
99
    }
100

101
    bool contains(const char* ptr) const
8,260✔
102
    {
103
        const char* buffer_end = this->sb_data + this->sb_length;
8,260✔
104

105
        return (this->sb_data <= ptr && ptr < buffer_end);
8,260✔
106
    }
107

108
    const file_range::metadata& get_metadata() const { return this->sb_metadata; }
1,625✔
109

110
    file_range::metadata& get_metadata() { return this->sb_metadata; }
137,690✔
111

112
    char* get_writable_data(size_t length)
200✔
113
    {
114
        if (this->take_ownership(length)) {
200✔
115
            return const_cast<char*>(this->sb_data);
200✔
116
        }
117

118
        return nullptr;
×
119
    }
120

121
    char* get_writable_data()
200✔
122
    {
123
        return this->get_writable_data(this->sb_length);
200✔
124
    }
125

126
    string_fragment to_string_fragment(off_t offset, size_t len) const
176✔
127
    {
128
        return string_fragment{
352✔
129
            this->sb_data, (int) offset, (int) (offset + len)};
176✔
130
    }
131

132
    string_fragment to_string_fragment(const line_range& lr) const
176✔
133
    {
134
        if (!lr.is_valid()) {
176✔
UNCOV
135
            return string_fragment::invalid();
×
136
        }
137

138
        return this->to_string_fragment(lr.lr_start, lr.length());
176✔
139
    }
140

141
    string_fragment to_string_fragment() const
977,509✔
142
    {
143
        return string_fragment::from_bytes(this->sb_data, this->length());
977,509✔
144
    }
145

146
    std::string_view to_string_view(const line_range& lr) const
313,958✔
147
    {
148
        return std::string_view{
313,958✔
149
            this->get_data_at(lr.lr_start),
313,958✔
150
            static_cast<std::string_view::size_type>(lr.length()),
313,958✔
151
        };
313,958✔
152
    }
153

154
    std::string_view to_string_view() const
47✔
155
    {
156
        return std::string_view{
94✔
157
            this->sb_data,
47✔
158
            this->sb_length,
47✔
159
        };
47✔
160
    }
161

162
    using narrow_result = std::pair<const char*, size_t>;
163
    narrow_result narrow(size_t new_data, size_t new_length);
164

165
    void widen(narrow_result old_data_length);
166

167
    void share(shared_buffer& sb, const char* data, size_t len);
168

169
    bool subset(shared_buffer_ref& other, off_t offset, size_t len);
170

171
    void erase_ansi();
172

173
    bool take_ownership(size_t length);
174

175
    bool take_ownership() { return this->take_ownership(this->sb_length); }
2,707✔
176

177
    void disown();
178

179
private:
180
    void copy_ref(const shared_buffer_ref& other);
181

182
#if SHARED_BUFFER_TRACE
183
    auto_mem<char*> sb_backtrace;
184
#endif
185
    file_range::metadata sb_metadata;
186
    shared_buffer* sb_owner;
187
    const char* sb_data;
188
    size_t sb_length;
189
};
190

191
class shared_buffer {
192
public:
193
    ~shared_buffer() { this->invalidate_refs(); }
59,556✔
194

195
    void add_ref(shared_buffer_ref& ref) { this->sb_refs.push_back(&ref); }
114,803✔
196

197
    bool invalidate_refs()
70,392✔
198
    {
199
        bool retval = true;
70,392✔
200

201
        while (!this->sb_refs.empty()) {
73,099✔
202
            auto iter = this->sb_refs.begin();
2,707✔
203

204
            retval = retval && (*iter)->take_ownership();
2,707✔
205
        }
206

207
        return retval;
70,392✔
208
    }
209

210
    std::vector<shared_buffer_ref*> sb_refs;
211
};
212

213
inline std::string
214
to_string(const shared_buffer_ref& sbr)
6,020✔
215
{
216
    return {sbr.get_data(), sbr.length()};
18,060✔
217
}
218

219
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc