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

tstack / lnav / 20245728190-2749

15 Dec 2025 07:59PM UTC coverage: 68.864% (-0.07%) from 68.929%
20245728190-2749

push

github

tstack
[text_format] add plaintext type

Related to #1296

85 of 132 new or added lines in 24 files covered. (64.39%)

73 existing lines in 10 files now uncovered.

51605 of 74938 relevant lines covered (68.86%)

434003.35 hits per line

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

77.78
/src/big_array.hh
1
/**
2
 * Copyright (c) 2017, 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 big_array.hh
30
 */
31

32
#ifndef lnav_big_array_hh
33
#define lnav_big_array_hh
34

35
#include <sys/mman.h>
36
#include <unistd.h>
37

38
#include "base/lnav_log.hh"
39
#include "base/math_util.hh"
40

41
template<typename T>
42
struct big_array {
43
    static const size_t DEFAULT_INCREMENT = 100 * 1000;
44

45
    bool reserve(size_t size)
4,315✔
46
    {
47
        if (size < this->ba_capacity) {
4,315✔
48
            return false;
3,681✔
49
        }
50

51
        if (this->ba_ptr) {
634✔
52
            munmap(this->ba_ptr,
×
53
                   roundup_size(this->ba_capacity * sizeof(T), getpagesize()));
×
54
        }
55

56
        this->ba_capacity = size + DEFAULT_INCREMENT;
634✔
57
        void* result
58
            = mmap(nullptr,
634✔
59
                   roundup_size(this->ba_capacity * sizeof(T), getpagesize()),
634✔
60
                   PROT_READ | PROT_WRITE,
61
                   MAP_ANONYMOUS | MAP_PRIVATE,
62
                   -1,
63
                   0);
64

65
        ensure(result != MAP_FAILED);
634✔
66

67
        this->ba_ptr = (T*) result;
634✔
68

69
        return true;
634✔
70
    }
71

72
    void clear() { this->ba_size = 0; }
1,609✔
73

74
    size_t size() const { return this->ba_size; }
20,757✔
75

76
    void shrink_to(size_t new_size)
×
77
    {
78
        require(new_size <= this->ba_size);
×
79

80
        this->ba_size = new_size;
×
81
    }
82

83
    bool empty() const { return this->ba_size == 0; }
13,457✔
84

85
    void push_back(const T& val)
13,843✔
86
    {
87
        this->ba_ptr[this->ba_size] = val;
13,843✔
88
        this->ba_size += 1;
13,843✔
89
    }
13,843✔
90

91
    T& operator[](size_t index) { return this->ba_ptr[index]; }
32,836✔
92

93
    const T& operator[](size_t index) const { return this->ba_ptr[index]; }
241,784✔
94

UNCOV
95
    T& back() { return this->ba_ptr[this->ba_size - 1]; }
×
96

97
    using iterator = T*;
98

99
    iterator begin() { return this->ba_ptr; }
1,141✔
100

101
    iterator end() { return this->ba_ptr + this->ba_size; }
1,141✔
102

103
    T* ba_ptr{nullptr};
104
    size_t ba_size{0};
105
    size_t ba_capacity{0};
106
};
107

108
#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