mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-08-05 17:30:27 +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())
|
if (isbig())
|
||||||
__builtin_trap();
|
__builtin_trap();
|
||||||
return reinterpret_cast<__::small_string*>(blob);
|
return &__s;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const __::small_string* small() const noexcept
|
inline const __::small_string* small() const noexcept
|
||||||
{
|
{
|
||||||
if (isbig())
|
if (isbig())
|
||||||
__builtin_trap();
|
__builtin_trap();
|
||||||
return reinterpret_cast<const __::small_string*>(blob);
|
return &__s;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline __::big_string* big() noexcept
|
inline __::big_string* big() noexcept
|
||||||
{
|
{
|
||||||
if (!isbig())
|
if (!isbig())
|
||||||
__builtin_trap();
|
__builtin_trap();
|
||||||
return reinterpret_cast<__::big_string*>(blob);
|
return &__b;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const __::big_string* big() const noexcept
|
inline const __::big_string* big() const noexcept
|
||||||
{
|
{
|
||||||
if (!isbig())
|
if (!isbig())
|
||||||
__builtin_trap();
|
__builtin_trap();
|
||||||
return reinterpret_cast<const __::big_string*>(blob);
|
return &__b;
|
||||||
}
|
}
|
||||||
|
|
||||||
friend string strcat(string_view, string_view);
|
friend string strcat(string_view, string_view);
|
||||||
|
|
||||||
alignas(union {
|
union
|
||||||
__::big_string a;
|
{
|
||||||
__::small_string b;
|
__::big_string __b;
|
||||||
}) char blob[__::string_size];
|
__::small_string __s;
|
||||||
|
char blob[__::string_size];
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
static_assert(sizeof(string) == __::string_size);
|
static_assert(sizeof(string) == __::string_size);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue