| Line |
Branch |
Exec |
Source |
| 1 |
|
|
#include <cstdlib> |
| 2 |
|
|
#include <cstdint> |
| 3 |
|
|
#include <cstring> |
| 4 |
|
|
#include "table.h" |
| 5 |
|
|
|
| 6 |
|
865 |
table::table() { |
| 7 |
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 483 times.
|
865 |
memset(data, 0, sizeof(data)); |
| 8 |
|
865 |
utf8_mode = true; |
| 9 |
|
865 |
} |
| 10 |
|
|
|
| 11 |
|
1722 |
void table::clear() { |
| 12 |
2/2
✓ Branch 0 taken 440832 times.
✓ Branch 1 taken 1722 times.
|
442554 |
for(int i=0; i<256; i++) { |
| 13 |
4/4
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 195295 times.
✓ Branch 2 taken 33 times.
✓ Branch 3 taken 245471 times.
|
440832 |
if(data[i] != nullptr) { |
| 14 |
2/2
✓ Branch 0 taken 16896 times.
✓ Branch 1 taken 66 times.
|
16962 |
for(int j=0; j<256; j++) { |
| 15 |
4/4
✓ Branch 0 taken 45 times.
✓ Branch 1 taken 8403 times.
✓ Branch 2 taken 45 times.
✓ Branch 3 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 0 not taken.
✓ Branch 1 taken 959 times.
|
1722 |
memset(data, 0, sizeof(data)); |
| 21 |
|
1722 |
} |
| 22 |
|
|
|
| 23 |
|
859 |
void table::copy_from(const table& from) { |
| 24 |
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 476 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 476 times.
|
859 |
memcpy(data, from.data, sizeof(data)); |
| 25 |
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 476 times.
|
859 |
utf8_mode = from.utf8_mode; |
| 26 |
|
|
// copy over all allocated pages |
| 27 |
2/2
✓ Branch 0 taken 219904 times.
✓ Branch 1 taken 859 times.
|
220763 |
for(int i=0; i<256; i++) { |
| 28 |
4/4
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 98042 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 121850 times.
|
219904 |
if(data[i] != nullptr) { |
| 29 |
|
12 |
table_page** newp = (table_page**)calloc(256,sizeof(void*)); |
| 30 |
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
|
12 |
memcpy(newp, data[i], 256*sizeof(void*)); |
| 31 |
|
12 |
data[i] = newp; |
| 32 |
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
|
3084 |
for(int j=0; j<256; j++) { |
| 33 |
4/4
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1530 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 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 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
|
12 |
memcpy(newp, data[i][j], sizeof(table_page)); |
| 36 |
|
12 |
data[i][j] = newp; |
| 37 |
|
|
} |
| 38 |
|
|
} |
| 39 |
|
|
} |
| 40 |
|
|
} |
| 41 |
|
859 |
} |
| 42 |
|
|
|
| 43 |
|
859 |
table& table::operator=(const table& from) { |
| 44 |
|
859 |
clear(); |
| 45 |
|
859 |
copy_from(from); |
| 46 |
|
859 |
return *this; |
| 47 |
|
|
} |
| 48 |
|
|
|
| 49 |
|
✗ |
table::table(const table& from) { |
| 50 |
|
✗ |
copy_from(from); |
| 51 |
|
✗ |
} |
| 52 |
|
|
|
| 53 |
|
863 |
table::~table() { |
| 54 |
|
863 |
clear(); |
| 55 |
|
863 |
} |
| 56 |
|
|
|
| 57 |
|
396 |
void table::set_val(int off, uint32_t val) { |
| 58 |
4/4
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 171 times.
✓ Branch 2 taken 27 times.
✓ Branch 3 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 0 taken 39 times.
✓ Branch 1 taken 159 times.
✓ Branch 2 taken 39 times.
✓ Branch 3 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 0 not taken.
✓ Branch 1 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/5
✓ Branch 0 taken 562 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 580 times.
✓ Branch 3 taken 580 times.
✗ Branch 4 not taken.
|
1142 |
int64_t def = utf8_mode ? off : -1; |
| 74 |
|
1142 |
table_page** thisbank = data[off >> 16]; |
| 75 |
2/2
✓ Branch 0 taken 338 times.
✓ Branch 1 taken 804 times.
|
1142 |
if(thisbank == nullptr) return def; |
| 76 |
|
804 |
table_page* thispage = thisbank[(off >> 8) & 255]; |
| 77 |
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 804 times.
|
804 |
if(thispage == nullptr) return def; |
| 78 |
|
804 |
int idx = (off & 255) / 32; |
| 79 |
|
804 |
int bit = off % 32; |
| 80 |
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 402 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 402 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 402 times.
|
804 |
if(((thispage->defined[idx] >> bit) & 1) == 0) return def; |
| 81 |
|
804 |
return thispage->chars[off & 255]; |
| 82 |
|
|
} |
| 83 |
|
|
|