Skip to content

Commit

Permalink
Make big_string pod
Browse files Browse the repository at this point in the history
`big_string` is not pod which means it needs to be properly
constructed and destroyed. Instead make it POD and destroy it
manually in `string` destructor.
  • Loading branch information
alkis committed Jun 8, 2024
1 parent d44a7dc commit a8057bc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 21 deletions.
30 changes: 11 additions & 19 deletions ctl/string.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,19 @@

namespace ctl {

namespace __ {

big_string::~big_string() /* noexcept */
{
if (n) {
if (n >= c)
__builtin_trap();
if (p[n])
__builtin_trap();
}
if (c && !p)
__builtin_trap();
free(p);
}

} // namespace __

string::~string() /* noexcept */
string::~string() noexcept
{
if (isbig()) {
big()->~big_string();
auto* b = big();
if (b->n) {
if (b->n >= b->c)
__builtin_trap();
if (b->p[b->n])
__builtin_trap();
}
if (b->c && !b->p)
__builtin_trap();
free(b->p);
}
}

Expand Down
2 changes: 0 additions & 2 deletions ctl/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ struct big_string
size_t c : sizeof(size_t) * 8 - 1;
size_t big : 1 /* = 1 */;
#endif

~big_string() /* noexcept */;
};

} // namespace __
Expand Down

0 comments on commit a8057bc

Please sign in to comment.