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

ArkScript-lang / Ark / 13900345969

17 Mar 2025 01:13PM UTC coverage: 78.852% (-0.1%) from 78.956%
13900345969

push

github

SuperFola
refactor: remove a layer of indirection when accessing the scopes storage

9 of 12 new or added lines in 4 files covered. (75.0%)

185 existing lines in 3 files now uncovered.

5865 of 7438 relevant lines covered (78.85%)

81043.55 hits per line

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

60.34
/src/arkreactor/VM/ScopeView.cpp
1
#include <Ark/VM/ScopeView.hpp>
2

3
#include <limits>
4

5
namespace Ark::internal
6
{
7
    ScopeView::ScopeView(pair_t* storage, const std::size_t start) noexcept :
126,626✔
8
        m_storage(storage), m_start(start), m_size(0), m_min_id(std::numeric_limits<uint16_t>::max()), m_max_id(0)
126,626✔
9
    {}
253,252✔
10

11
    void ScopeView::push_back(uint16_t id, Value&& val) noexcept
17,104✔
12
    {
17,104✔
13
        if (id < m_min_id)
17,104✔
14
            m_min_id = id;
2,043✔
15
        if (id > m_max_id)
17,104✔
16
            m_max_id = id;
14,547✔
17

18
        m_storage[m_start + m_size] = std::make_pair(id, std::move(val));
17,104✔
19
        ++m_size;
17,104✔
20
    }
17,104✔
21

22
    void ScopeView::push_back(uint16_t id, const Value& val) noexcept
351,234✔
23
    {
351,234✔
24
        if (id < m_min_id)
351,234✔
25
            m_min_id = id;
130,930✔
26
        if (id > m_max_id)
351,234✔
27
            m_max_id = id;
223,328✔
28

29
        m_storage[m_start + m_size] = std::make_pair(id, val);
351,234✔
30
        ++m_size;
351,234✔
31
    }
351,234✔
32

33
    bool ScopeView::maybeHas(const uint16_t id) const noexcept
1,549,722✔
34
    {
1,549,722✔
35
        return m_min_id <= id && id <= m_max_id;
1,549,722✔
36
    }
37

38
    Value* ScopeView::operator[](const uint16_t id_to_look_for) noexcept
1,549,723✔
39
    {
1,549,723✔
40
        if (!maybeHas(id_to_look_for))
1,549,723✔
41
            return nullptr;
387,481✔
42

43
        for (std::size_t i = m_start; i < m_start + m_size; ++i)
4,210,968✔
44
        {
45
            auto& [id, value] = m_storage[i];
3,048,726✔
46
            if (id == id_to_look_for)
3,048,726✔
47
                return &value;
1,147,073✔
48
        }
3,048,726✔
49
        return nullptr;
15,171✔
50
    }
1,549,723✔
51

52
    const Value* ScopeView::operator[](const uint16_t id_to_look_for) const noexcept
×
53
    {
×
54
        if (!maybeHas(id_to_look_for))
×
55
            return nullptr;
×
56

57
        for (std::size_t i = m_start; i < m_start + m_size; ++i)
×
58
        {
NEW
59
            auto& [id, value] = m_storage[i];
×
60
            if (id == id_to_look_for)
×
61
                return &value;
×
62
        }
×
63
        return nullptr;
×
64
    }
×
65

66
    uint16_t ScopeView::idFromValue(const Value& val) const noexcept
×
67
    {
×
68
        for (std::size_t i = m_start; i < m_start + m_size; ++i)
×
69
        {
NEW
70
            const auto& [id, value] = m_storage[i];
×
71
            if (value == val)
×
72
                return id;
×
73
        }
×
74
        return std::numeric_limits<uint16_t>::max();
×
75
    }
×
76

77
    bool operator==(const ScopeView& A, const ScopeView& B) noexcept
×
78
    {
×
79
        // if we have two scopes with the same number of elements and starting at the same position,
80
        // they must be identical, as we have a single storage for all scopes
81
        return A.m_size == B.m_size && A.m_start == B.m_start;
×
82
    }
83
}
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