asar coverage - build #


src/asar/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
55 of 58, 0 excluded
94.8%
Functions:
7 of 8, 0 excluded
87.5%
Branches:
62 of 80, 0 excluded
77.5%

table.cpp
Line Branch Exec Source
1 #include <cstdlib>
2 #include <cstdint>
3 #include <cstring>
4 #include "table.h"
5
6 877 table::table() {
7
1/2
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 6 taken 489 times.
877 memset(data, 0, sizeof(data));
8 877 utf8_mode = true;
9 877 }
10
11 1746 void table::clear() {
12
4/4
✓ Branch 11 → 3 taken 198400 times.
✓ Branch 11 → 12 taken 775 times.
✓ Branch 23 → 3 taken 248576 times.
✓ Branch 23 → 24 taken 971 times.
448722 for(int i=0; i<256; i++) {
13
4/4
✓ Branch 3 → 4 taken 33 times.
✓ Branch 3 → 10 taken 198367 times.
✓ Branch 5 → 6 taken 33 times.
✓ Branch 5 → 22 taken 248543 times.
446976 if(data[i] != nullptr) {
14
4/4
✓ Branch 8 → 5 taken 8448 times.
✓ Branch 8 → 9 taken 33 times.
✓ Branch 18 → 7 taken 8448 times.
✓ Branch 18 → 19 taken 33 times.
16962 for(int j=0; j<256; j++) {
15
4/4
✓ Branch 5 → 6 taken 45 times.
✓ Branch 5 → 7 taken 8403 times.
✓ Branch 11 → 12 taken 45 times.
✓ Branch 11 → 17 taken 8403 times.
16896 if(data[i][j] != nullptr) free(data[i][j]);
16 }
17 66 free(data[i]);
18 }
19 }
20
1/2
✗ Branch 26 → 27 not taken.
✓ Branch 26 → 28 taken 971 times.
1746 memset(data, 0, sizeof(data));
21 1746 }
22
23 871 void table::copy_from(const table& from) {
24
2/4
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 482 times.
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 10 taken 482 times.
871 memcpy(data, from.data, sizeof(data));
25
1/2
✗ Branch 11 → 12 not taken.
✓ Branch 11 → 13 taken 482 times.
871 utf8_mode = from.utf8_mode;
26 // copy over all allocated pages
27
4/4
✓ Branch 10 → 3 taken 99584 times.
✓ Branch 10 → 11 taken 389 times.
✓ Branch 48 → 15 taken 123392 times.
✓ Branch 48 → 49 taken 482 times.
223847 for(int i=0; i<256; i++) {
28
4/4
✓ Branch 3 → 4 taken 6 times.
✓ Branch 3 → 9 taken 99578 times.
✓ Branch 17 → 18 taken 6 times.
✓ Branch 17 → 47 taken 123386 times.
222976 if(data[i] != nullptr) {
29 12 table_page** newp = (table_page**)calloc(256,sizeof(void*));
30
2/4
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 22 taken 6 times.
✗ Branch 22 → 23 not taken.
✓ Branch 22 → 24 taken 6 times.
12 memcpy(newp, data[i], 256*sizeof(void*));
31 12 data[i] = newp;
32
4/4
✓ Branch 8 → 5 taken 1536 times.
✓ Branch 8 → 9 taken 6 times.
✓ Branch 46 → 27 taken 1536 times.
✓ Branch 46 → 47 taken 6 times.
3084 for(int j=0; j<256; j++) {
33
4/4
✓ Branch 5 → 6 taken 6 times.
✓ Branch 5 → 7 taken 1530 times.
✓ Branch 31 → 32 taken 6 times.
✓ Branch 31 → 45 taken 1530 times.
3072 if(data[i][j] != nullptr) {
34 12 table_page* newp = (table_page*)calloc(1,sizeof(table_page));
35
2/4
✗ Branch 36 → 37 not taken.
✓ Branch 36 → 38 taken 6 times.
✗ Branch 38 → 39 not taken.
✓ Branch 38 → 40 taken 6 times.
12 memcpy(newp, data[i][j], sizeof(table_page));
36 12 data[i][j] = newp;
37 }
38 }
39 }
40 }
41 871 }
42
43 871 table& table::operator=(const table& from) {
44 871 clear();
45 871 copy_from(from);
46 871 return *this;
47 }
48
49 table::table(const table& from) {
50 copy_from(from);
51 }
52
53 875 table::~table() {
54 875 clear();
55 875 }
56
57 396 void table::set_val(int off, uint32_t val) {
58
4/4
✓ Branch 2 → 3 taken 27 times.
✓ Branch 2 → 4 taken 171 times.
✓ Branch 4 → 5 taken 27 times.
✓ Branch 4 → 8 taken 171 times.
396 if(data[off >> 16] == nullptr) {
59 54 data[off >> 16] = (table_page**)calloc(256,sizeof(void*));
60 }
61 396 table_page** thisbank = data[off >> 16];
62
4/4
✓ Branch 4 → 5 taken 39 times.
✓ Branch 4 → 6 taken 159 times.
✓ Branch 12 → 13 taken 39 times.
✓ Branch 12 → 16 taken 159 times.
396 if(thisbank[(off >> 8) & 255] == nullptr) {
63 78 thisbank[(off >> 8) & 255] = (table_page*)calloc(1,sizeof(table_page));
64 }
65 396 table_page* thispage = thisbank[(off >> 8) & 255];
66 396 int idx = (off & 255) / 32;
67 396 int bit = off % 32;
68
1/2
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 22 taken 198 times.
396 thispage->defined[idx] |= 1<<bit;
69 396 thispage->chars[off & 255] = val;
70 396 }
71
72 1142 int64_t table::get_val(int off) {
73
3/6
✓ Branch 2 → 3 taken 562 times.
✗ Branch 2 → 4 not taken.
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 580 times.
✓ Branch 5 → 6 taken 580 times.
✗ Branch 5 → 7 not taken.
1142 int64_t def = utf8_mode ? off : -1;
74 1142 table_page** thisbank = data[off >> 16];
75
4/4
✓ Branch 5 → 6 taken 160 times.
✓ Branch 5 → 7 taken 402 times.
✓ Branch 10 → 11 taken 178 times.
✓ Branch 10 → 12 taken 402 times.
1142 if(thisbank == nullptr) return def;
76 804 table_page* thispage = thisbank[(off >> 8) & 255];
77
2/4
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 9 taken 402 times.
✗ Branch 14 → 15 not taken.
✓ Branch 14 → 16 taken 402 times.
804 if(thispage == nullptr) return def;
78 804 int idx = (off & 255) / 32;
79 804 int bit = off % 32;
80
3/6
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 11 taken 402 times.
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 22 taken 402 times.
✗ Branch 22 → 23 not taken.
✓ Branch 22 → 24 taken 402 times.
804 if(((thispage->defined[idx] >> bit) & 1) == 0) return def;
81 804 return thispage->chars[off & 255];
82 }
83