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

Tehreer / SheenBidi / 16018107986

02 Jul 2025 06:48AM UTC coverage: 96.598% (+0.8%) from 95.795%
16018107986

push

github

mta452
[test] Add allocator tests in combined tests execution

2215 of 2293 relevant lines covered (96.6%)

783098.39 hits per line

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

97.27
/Source/BracketQueue.c
1
/*
2
 * Copyright (C) 2014-2025 Muhammad Tayyab Akram
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16

17
#include <stddef.h>
18

19
#include <SheenBidi/SBBase.h>
20
#include <SheenBidi/SBConfig.h>
21

22
#include "BidiChain.h"
23
#include "Memory.h"
24
#include "SBAssert.h"
25
#include "SBCodepoint.h"
26
#include "BracketQueue.h"
27

28
static SBBoolean BracketQueueInsertElement(BracketQueueRef queue)
329,475✔
29
{
30
    if (queue->_rearTop != BracketQueueList_MaxIndex) {
329,475✔
31
        queue->_rearTop += 1;
329,454✔
32
    } else {
33
        BracketQueueListRef previousList = queue->_rearList;
21✔
34
        BracketQueueListRef rearList = previousList->next;
21✔
35

36
        if (!rearList) {
21✔
37
            rearList = MemoryAllocateBlock(queue->_memory, MemoryTypeScratch, sizeof(BracketQueueList));
21✔
38
            if (!rearList) {
21✔
39
                return SBFalse;
×
40
            }
41

42
            rearList->previous = previousList;
21✔
43
            rearList->next = NULL;
21✔
44

45
            previousList->next = rearList;
21✔
46
        }
47

48
        queue->_rearList = rearList;
21✔
49
        queue->_rearTop = 0;
21✔
50
    }
51
    queue->count += 1;
329,475✔
52

53
    return SBTrue;
329,475✔
54
}
55

56
static void BracketQueueFinalizePairs(BracketQueueRef queue, BracketQueueListRef list, SBInteger top)
139,723✔
57
{
58
    do {
59
        SBInteger limit = (list == queue->_rearList ? queue->_rearTop : BracketQueueList_MaxIndex);
140,171✔
60

61
        while (++top <= limit) {
188,195✔
62
            if (list->openingLink[top] != BidiLinkNone
48,024✔
63
                && list->closingLink[top] == BidiLinkNone) {
48,016✔
64
                list->openingLink[top] = BidiLinkNone;
20,528✔
65
            }
66
        }
67

68
        list = list->next;
140,171✔
69
        top = 0;
140,171✔
70
    } while (list);
140,171✔
71
}
139,723✔
72

73
SB_INTERNAL void BracketQueueInitialize(BracketQueueRef queue, MemoryRef memory)
861,949✔
74
{
75
    queue->_memory = memory;
861,949✔
76
    queue->_firstList.previous = NULL;
861,949✔
77
    queue->_firstList.next = NULL;
861,949✔
78
    queue->_frontList = NULL;
861,949✔
79
    queue->_rearList = NULL;
861,949✔
80
    queue->count = 0;
861,949✔
81
    queue->shouldDequeue = SBFalse;
861,949✔
82
}
861,949✔
83

84
SB_INTERNAL void BracketQueueReset(BracketQueueRef queue, SBBidiType direction)
1,257,049✔
85
{
86
    queue->_frontList = &queue->_firstList;
1,257,049✔
87
    queue->_rearList = &queue->_firstList;
1,257,049✔
88
    queue->_frontTop = 0;
1,257,049✔
89
    queue->_rearTop = -1;
1,257,049✔
90
    queue->count = 0;
1,257,049✔
91
    queue->shouldDequeue = SBFalse;
1,257,049✔
92
    queue->_direction = direction;
1,257,049✔
93
}
1,257,049✔
94

95
SB_INTERNAL SBBoolean BracketQueueEnqueue(BracketQueueRef queue,
329,475✔
96
   BidiLink priorStrongLink, BidiLink openingLink, SBCodepoint bracket)
97
{
98
    /* The queue can only take a maximum of 63 elements. */
99
    SBAssert(queue->count < BracketQueueGetMaxCapacity());
329,475✔
100

101
    if (BracketQueueInsertElement(queue)) {
329,475✔
102
        BracketQueueListRef list = queue->_rearList;
329,475✔
103
        SBInteger top = queue->_rearTop;
329,475✔
104

105
        list->priorStrongLink[top] = priorStrongLink;
329,475✔
106
        list->openingLink[top] = openingLink;
329,475✔
107
        list->closingLink[top] = BidiLinkNone;
329,475✔
108
        list->bracket[top] = bracket;
329,475✔
109
        list->strongType[top] = SBBidiTypeNil;
329,475✔
110

111
        return SBTrue;
329,475✔
112
    }
113

114
    return SBFalse;
×
115
}
116

117
SB_INTERNAL void BracketQueueDequeue(BracketQueueRef queue)
329,475✔
118
{
119
    /* The queue must NOT be empty. */
120
    SBAssert(queue->count != 0);
329,475✔
121

122
    if (queue->_frontTop != BracketQueueList_MaxIndex) {
329,475✔
123
        queue->_frontTop += 1;
329,454✔
124
    } else {
125
        BracketQueueListRef frontList = queue->_frontList;
21✔
126

127
        if (frontList == queue->_rearList) {
21✔
128
            queue->_rearTop = -1;
×
129
        } else {
130
            queue->_frontList = frontList->next;
21✔
131
        }
132

133
        queue->_frontTop = 0;
21✔
134
    }
135

136
    queue->count -= 1;
329,475✔
137
}
329,475✔
138

139
SB_INTERNAL void BracketQueueSetStrongType(BracketQueueRef queue, SBBidiType strongType)
186,688✔
140
{
141
    BracketQueueListRef list = queue->_rearList;
186,688✔
142
    SBInteger top = queue->_rearTop;
186,688✔
143

144
    while (1) {
14✔
145
        SBInteger limit = (list == queue->_frontList ? queue->_frontTop : 0);
186,702✔
146

147
        do {
148
            if (list->closingLink[top] == BidiLinkNone
315,203✔
149
                && list->strongType[top] != queue->_direction) {
265,403✔
150
                list->strongType[top] = strongType;
206,184✔
151
            }
152
        } while (top-- > limit);
315,203✔
153

154
        if (list == queue->_frontList) {
186,702✔
155
            break;
186,688✔
156
        }
157

158
        list = list->previous;
14✔
159
        top = BracketQueueList_MaxIndex;
14✔
160
    }
161
}
186,688✔
162

163
SB_INTERNAL void BracketQueueClosePair(BracketQueueRef queue, BidiLink closingLink, SBCodepoint bracket)
154,290✔
164
{
165
    BracketQueueListRef list = queue->_rearList;
154,290✔
166
    SBInteger top = queue->_rearTop;
154,290✔
167

168
    while (1) {
448✔
169
        SBBoolean isFrontList = (list == queue->_frontList);
154,738✔
170
        SBInteger limit = (isFrontList ? queue->_frontTop : 0);
154,738✔
171

172
        do {
173
            if (list->openingLink[top] != BidiLinkNone
227,002✔
174
                && list->closingLink[top] == BidiLinkNone
214,876✔
175
                && SBCodepointIsCanonicalEquivalentBracket(list->bracket[top], bracket)) {
174,818✔
176
                list->closingLink[top] = closingLink;
139,723✔
177
                BracketQueueFinalizePairs(queue, list, top);
139,723✔
178

179
                if (isFrontList && top == queue->_frontTop) {
139,723✔
180
                    queue->shouldDequeue = SBTrue;
62,172✔
181
                }
182

183
                return;
139,723✔
184
            }
185
        } while (top-- > limit);
87,279✔
186

187
        if (isFrontList) {
15,015✔
188
            break;
14,567✔
189
        }
190

191
        list = list->previous;
448✔
192
        top = BracketQueueList_MaxIndex;
448✔
193
    }
194
}
195

196
SB_INTERNAL SBBoolean BracketQueueShouldDequeue(BracketQueueRef queue)
154,290✔
197
{
198
    return queue->shouldDequeue;
154,290✔
199
}
200

201
SB_INTERNAL BidiLink BracketQueueGetPriorStrongLink(BracketQueueRef queue)
28,864✔
202
{
203
    return queue->_frontList->priorStrongLink[queue->_frontTop];
28,864✔
204
}
205

206
SB_INTERNAL BidiLink BracketQueueGetOpeningLink(BracketQueueRef queue)
329,475✔
207
{
208
    return queue->_frontList->openingLink[queue->_frontTop];
329,475✔
209
}
210

211
SB_INTERNAL BidiLink BracketQueueGetClosingLink(BracketQueueRef queue)
329,475✔
212
{
213
    return queue->_frontList->closingLink[queue->_frontTop];
329,475✔
214
}
215

216
SB_INTERNAL SBBidiType BracketQueueGetStrongType(BracketQueueRef queue)
139,723✔
217
{
218
    return queue->_frontList->strongType[queue->_frontTop];
139,723✔
219
}
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