summaryrefslogtreecommitdiff
path: root/src/string.hh
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2024-06-12 20:17:10 +1000
committerMaxime Coste <mawww@kakoune.org>2024-06-12 20:18:00 +1000
commit966deb514e8a2af5f4c8ae31143b98ac06a1eb51 (patch)
tree4ecd6f7ac851af099e7bc98c33d4fdabe9e90844 /src/string.hh
parentfe8f0f3371f535602dbcd641e78dbe18f449bc87 (diff)
Add some static_asserts in SSO code
Diffstat (limited to 'src/string.hh')
-rw-r--r--src/string.hh8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/string.hh b/src/string.hh
index 857a1b19..01e91b62 100644
--- a/src/string.hh
+++ b/src/string.hh
@@ -200,15 +200,16 @@ public:
private:
struct Long
{
- static constexpr size_t max_capacity =
- ((size_t)1 << (CHAR_BIT * (sizeof(size_t) - 1))) - 1;
+ static constexpr size_t capacity_bits = CHAR_BIT * (sizeof(size_t) - 1);
+ static constexpr size_t max_capacity = ((size_t)1 << capacity_bits) - 1;
char* ptr;
size_t size;
- size_t capacity: (sizeof(size_t) - 1) *CHAR_BIT;
+ size_t capacity : capacity_bits;
unsigned char mode;
static constexpr unsigned char active_mask = 0b1000'0000;
};
+ static_assert(sizeof(Long) == sizeof(char*) * 3);
struct Short
{
@@ -219,6 +220,7 @@ public:
// and not collide with Long::active_mask.
unsigned char remaining_size;
};
+ static_assert(offsetof(Long, mode) == offsetof(Short, remaining_size));
union
{