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

ArkScript-lang / Ark / 13821805922

12 Mar 2025 09:16PM UTC coverage: 78.956% (+0.03%) from 78.931%
13821805922

push

github

SuperFola
feat(tests): update binary trees benchmark to use closures

5853 of 7413 relevant lines covered (78.96%)

80211.69 hits per line

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

72.37
/src/arkreactor/VM/Scope.cpp
1
#include <Ark/VM/Scope.hpp>
2

3
#include <limits>
4

5
namespace Ark::internal
6
{
7
    Scope::Scope() noexcept :
126,714✔
8
        m_min_id(std::numeric_limits<uint16_t>::max()), m_max_id(0)
126,714✔
9
    {
126,714✔
10
        m_data.reserve(3);
126,714✔
11
    }
126,714✔
12

13
    void Scope::mergeRefInto(Scope& other)
1,978✔
14
    {
1,978✔
15
        for (auto& [id, val] : m_data)
36,186✔
16
        {
17
            if (val.valueType() == ValueType::Reference)
17,104✔
18
                other.push_back(id, val);
×
19
            else
20
                other.push_back(id, Value(&val));
17,104✔
21
        }
17,104✔
22
    }
1,978✔
23

24
    void Scope::push_back(uint16_t id, Value&& val) noexcept
17,104✔
25
    {
17,104✔
26
        if (id < m_min_id)
17,104✔
27
            m_min_id = id;
2,043✔
28
        if (id > m_max_id)
17,104✔
29
            m_max_id = id;
14,547✔
30

31
        m_data.emplace_back(id, std::move(val));
17,104✔
32
    }
17,104✔
33

34
    void Scope::push_back(uint16_t id, const Value& val) noexcept
351,691✔
35
    {
351,691✔
36
        if (id < m_min_id)
351,691✔
37
            m_min_id = id;
131,038✔
38
        if (id > m_max_id)
351,691✔
39
            m_max_id = id;
223,761✔
40

41
        m_data.emplace_back(id, val);
351,691✔
42
    }
351,691✔
43

44
    bool Scope::maybeHas(const uint16_t id) const noexcept
1,551,146✔
45
    {
1,551,146✔
46
        return m_min_id <= id && id <= m_max_id;
1,551,146✔
47
    }
48

49
    Value* Scope::operator[](const uint16_t id_to_look_for) noexcept
1,551,064✔
50
    {
1,551,064✔
51
        if (!maybeHas(id_to_look_for))
1,551,064✔
52
            return nullptr;
387,378✔
53

54
        for (auto& [id, value] : m_data)
4,224,519✔
55
        {
56
            if (id == id_to_look_for)
3,060,833✔
57
                return &value;
1,148,524✔
58
        }
3,060,833✔
59
        return nullptr;
15,171✔
60
    }
1,551,064✔
61

62
    const Value* Scope::operator[](const uint16_t id_to_look_for) const noexcept
×
63
    {
×
64
        if (!maybeHas(id_to_look_for))
×
65
            return nullptr;
×
66

67
        for (const auto& [id, value] : m_data)
×
68
        {
69
            if (id == id_to_look_for)
×
70
                return &value;
×
71
        }
×
72
        return nullptr;
×
73
    }
×
74

75
    uint16_t Scope::idFromValue(const Value& val) const noexcept
×
76
    {
×
77
        for (const auto& [id, data] : m_data)
×
78
        {
79
            if (data == val)
×
80
                return id;
×
81
        }
×
82
        return std::numeric_limits<uint16_t>::max();
×
83
    }
×
84

85
    std::size_t Scope::size() const noexcept
18✔
86
    {
18✔
87
        return m_data.size();
18✔
88
    }
89

90
    bool operator==(const Scope& A, const Scope& B) noexcept
9✔
91
    {
9✔
92
        const std::size_t size = A.size();
9✔
93
        if (size != B.size())
9✔
94
            return false;
×
95
        if (A.m_min_id != B.m_min_id || A.m_max_id != B.m_max_id)
9✔
96
            return false;
×
97

98
        // assuming we have the same closure page address, the element should be in the same order
99
        for (std::size_t i = 0; i < size; ++i)
27✔
100
        {
101
            if (A.m_data[i] != B.m_data[i])
18✔
102
                return false;
2✔
103
        }
16✔
104

105
        return true;
7✔
106
    }
9✔
107
}
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