| Line |
Branch |
Exec |
Source |
| 1 |
|
|
#include <cstdlib> |
| 2 |
|
|
#include <cstdint> |
| 3 |
|
|
#include <cstring> |
| 4 |
|
|
#include "table.h" |
| 5 |
|
|
|
| 6 |
|
2773 |
table::table() { |
| 7 |
|
2773 |
memset(data, 0, sizeof(data)); |
| 8 |
|
2773 |
utf8_mode = true; |
| 9 |
|
2773 |
} |
| 10 |
|
|
|
| 11 |
|
4806 |
void table::clear() { |
| 12 |
2/2
✓ Branch 0 taken 1230336 times.
✓ Branch 1 taken 4806 times.
|
1235142 |
for(int i=0; i<256; i++) { |
| 13 |
2/2
✓ Branch 0 taken 190 times.
✓ Branch 1 taken 1230146 times.
|
1230336 |
if(data[i] != nullptr) { |
| 14 |
2/2
✓ Branch 0 taken 48640 times.
✓ Branch 1 taken 190 times.
|
48830 |
for(int j=0; j<256; j++) { |
| 15 |
2/2
✓ Branch 0 taken 258 times.
✓ Branch 1 taken 48382 times.
|
48640 |
if(data[i][j] != nullptr) free(data[i][j]); |
| 16 |
|
|
} |
| 17 |
|
190 |
free(data[i]); |
| 18 |
|
|
} |
| 19 |
|
|
} |
| 20 |
|
4806 |
memset(data, 0, sizeof(data)); |
| 21 |
|
4806 |
} |
| 22 |
|
|
|
| 23 |
|
2283 |
void table::copy_from(const table& from) { |
| 24 |
|
2283 |
memcpy(data, from.data, sizeof(data)); |
| 25 |
|
2283 |
utf8_mode = from.utf8_mode; |
| 26 |
|
|
// copy over all allocated pages |
| 27 |
2/2
✓ Branch 0 taken 584448 times.
✓ Branch 1 taken 2283 times.
|
586731 |
for(int i=0; i<256; i++) { |
| 28 |
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 584412 times.
|
584448 |
if(data[i] != nullptr) { |
| 29 |
|
36 |
table_page** newp = (table_page**)calloc(256,sizeof(void*)); |
| 30 |
|
36 |
memcpy(newp, data[i], 256*sizeof(void*)); |
| 31 |
|
36 |
data[i] = newp; |
| 32 |
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 36 times.
|
9252 |
for(int j=0; j<256; j++) { |
| 33 |
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 9180 times.
|
9216 |
if(data[i][j] != nullptr) { |
| 34 |
|
36 |
table_page* newp = (table_page*)calloc(1,sizeof(table_page)); |
| 35 |
|
36 |
memcpy(newp, data[i][j], sizeof(table_page)); |
| 36 |
|
36 |
data[i][j] = newp; |
| 37 |
|
|
} |
| 38 |
|
|
} |
| 39 |
|
|
} |
| 40 |
|
|
} |
| 41 |
|
2283 |
} |
| 42 |
|
|
|
| 43 |
|
2283 |
table& table::operator=(const table& from) { |
| 44 |
|
2283 |
clear(); |
| 45 |
|
2283 |
copy_from(from); |
| 46 |
|
2283 |
return *this; |
| 47 |
|
|
} |
| 48 |
|
|
|
| 49 |
|
✗ |
table::table(const table& from) { |
| 50 |
|
✗ |
copy_from(from); |
| 51 |
|
✗ |
} |
| 52 |
|
|
|
| 53 |
|
2523 |
table::~table() { |
| 54 |
|
2523 |
clear(); |
| 55 |
|
2523 |
} |
| 56 |
|
|
|
| 57 |
|
1188 |
void table::set_val(int off, uint32_t val) { |
| 58 |
2/2
✓ Branch 0 taken 162 times.
✓ Branch 1 taken 1026 times.
|
1188 |
if(data[off >> 16] == nullptr) { |
| 59 |
|
162 |
data[off >> 16] = (table_page**)calloc(256,sizeof(void*)); |
| 60 |
|
|
} |
| 61 |
|
1188 |
table_page** thisbank = data[off >> 16]; |
| 62 |
2/2
✓ Branch 0 taken 234 times.
✓ Branch 1 taken 954 times.
|
1188 |
if(thisbank[(off >> 8) & 255] == nullptr) { |
| 63 |
|
234 |
thisbank[(off >> 8) & 255] = (table_page*)calloc(1,sizeof(table_page)); |
| 64 |
|
|
} |
| 65 |
|
1188 |
table_page* thispage = thisbank[(off >> 8) & 255]; |
| 66 |
|
1188 |
int idx = (off & 255) / 32; |
| 67 |
|
594 |
int bit = off % 32; |
| 68 |
|
1188 |
thispage->defined[idx] |= 1<<bit; |
| 69 |
|
1188 |
thispage->chars[off & 255] = val; |
| 70 |
|
1188 |
} |
| 71 |
|
|
|
| 72 |
|
3378 |
int64_t table::get_val(int off) { |
| 73 |
1/2
✓ Branch 0 taken 3378 times.
✗ Branch 1 not taken.
|
3378 |
int64_t def = utf8_mode ? off : -1; |
| 74 |
|
3378 |
table_page** thisbank = data[off >> 16]; |
| 75 |
2/2
✓ Branch 0 taken 1698 times.
✓ Branch 1 taken 1680 times.
|
3378 |
if(thisbank == nullptr) return def; |
| 76 |
|
2412 |
table_page* thispage = thisbank[(off >> 8) & 255]; |
| 77 |
2/2
✓ Branch 0 taken 1206 times.
✓ Branch 1 taken 1206 times.
|
2412 |
if(thispage == nullptr) return def; |
| 78 |
|
2412 |
int idx = (off & 255) / 32; |
| 79 |
|
1206 |
int bit = off % 32; |
| 80 |
2/2
✓ Branch 0 taken 1206 times.
✓ Branch 1 taken 1206 times.
|
2412 |
if(((thispage->defined[idx] >> bit) & 1) == 0) return def; |
| 81 |
|
2412 |
return thispage->chars[off & 255]; |
| 82 |
|
|
} |
| 83 |
|
|
|