| 1266 | } |
| 1267 | |
| 1268 | void das_table_clear ( das_context * context, das_table * tab, int key_base_type, uint32_t value_size ) { |
| 1269 | auto * t = (Table *)tab; |
| 1270 | if ( t->isLocked() ) { |
| 1271 | ((Context *)context)->throw_error("can't clear locked table"); |
| 1272 | return; |
| 1273 | } |
| 1274 | if ( t->data ) { |
| 1275 | uint32_t key_size = 0; |
| 1276 | DAS_TABLE_DISPATCH(key_base_type, { key_size = sizeof(KEY_TYPE); }) |
| 1277 | if ( !key_size ) return; // throw_error already raised |
| 1278 | uint64_t total = t->capacity * (uint64_t(value_size) + uint64_t(key_size)) + t->capacity*das::tableHashSlotBytes(*t); |
| 1279 | ((Context *)context)->free(t->data, total, nullptr); |
| 1280 | } |
| 1281 | memset(t, 0, sizeof(Table)); |
| 1282 | } |
| 1283 | |
| 1284 | // `key` may point at unaligned bytes (a key inside a packed buffer, an |
| 1285 | // offset inside a serialization stream, …) — copy into an aligned local |
no test coverage detected