mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-08-03 08:20:28 +00:00
Just use the anonymous union
This commit is contained in:
parent
e2f19d5173
commit
0cf4617828
1 changed files with 10 additions and 8 deletions
18
ctl/string.h
18
ctl/string.h
|
@ -350,36 +350,38 @@ class string
|
|||
{
|
||||
if (isbig())
|
||||
__builtin_trap();
|
||||
return reinterpret_cast<__::small_string*>(blob);
|
||||
return &__s;
|
||||
}
|
||||
|
||||
inline const __::small_string* small() const noexcept
|
||||
{
|
||||
if (isbig())
|
||||
__builtin_trap();
|
||||
return reinterpret_cast<const __::small_string*>(blob);
|
||||
return &__s;
|
||||
}
|
||||
|
||||
inline __::big_string* big() noexcept
|
||||
{
|
||||
if (!isbig())
|
||||
__builtin_trap();
|
||||
return reinterpret_cast<__::big_string*>(blob);
|
||||
return &__b;
|
||||
}
|
||||
|
||||
inline const __::big_string* big() const noexcept
|
||||
{
|
||||
if (!isbig())
|
||||
__builtin_trap();
|
||||
return reinterpret_cast<const __::big_string*>(blob);
|
||||
return &__b;
|
||||
}
|
||||
|
||||
friend string strcat(string_view, string_view);
|
||||
|
||||
alignas(union {
|
||||
__::big_string a;
|
||||
__::small_string b;
|
||||
}) char blob[__::string_size];
|
||||
union
|
||||
{
|
||||
__::big_string __b;
|
||||
__::small_string __s;
|
||||
char blob[__::string_size];
|
||||
};
|
||||
};
|
||||
|
||||
static_assert(sizeof(string) == __::string_size);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue