1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-08-17 00:30:26 +03:00

Add some static_asserts in SSO code

This commit is contained in:
Maxime Coste 2024-06-12 20:17:10 +10:00
parent fe8f0f3371
commit 966deb514e

View File

@ -200,15 +200,16 @@ public:
private: private:
struct Long struct Long
{ {
static constexpr size_t max_capacity = static constexpr size_t capacity_bits = CHAR_BIT * (sizeof(size_t) - 1);
((size_t)1 << (CHAR_BIT * (sizeof(size_t) - 1))) - 1; static constexpr size_t max_capacity = ((size_t)1 << capacity_bits) - 1;
char* ptr; char* ptr;
size_t size; size_t size;
size_t capacity: (sizeof(size_t) - 1) *CHAR_BIT; size_t capacity : capacity_bits;
unsigned char mode; unsigned char mode;
static constexpr unsigned char active_mask = 0b1000'0000; static constexpr unsigned char active_mask = 0b1000'0000;
}; };
static_assert(sizeof(Long) == sizeof(char*) * 3);
struct Short struct Short
{ {
@ -219,6 +220,7 @@ public:
// and not collide with Long::active_mask. // and not collide with Long::active_mask.
unsigned char remaining_size; unsigned char remaining_size;
}; };
static_assert(offsetof(Long, mode) == offsetof(Short, remaining_size));
union union
{ {