Skip to content

Commit a0410f0

Browse files
authored
Make big_string pod (#1204)
`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.
1 parent d44a7dc commit a0410f0

File tree

2 files changed

+11
-21
lines changed

2 files changed

+11
-21
lines changed

ctl/string.cc

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,19 @@
2323

2424
namespace ctl {
2525

26-
namespace __ {
27-
28-
big_string::~big_string() /* noexcept */
29-
{
30-
if (n) {
31-
if (n >= c)
32-
__builtin_trap();
33-
if (p[n])
34-
__builtin_trap();
35-
}
36-
if (c && !p)
37-
__builtin_trap();
38-
free(p);
39-
}
40-
41-
} // namespace __
42-
43-
string::~string() /* noexcept */
26+
string::~string() noexcept
4427
{
4528
if (isbig()) {
46-
big()->~big_string();
29+
auto* b = big();
30+
if (b->n) {
31+
if (b->n >= b->c)
32+
__builtin_trap();
33+
if (b->p[b->n])
34+
__builtin_trap();
35+
}
36+
if (b->c && !b->p)
37+
__builtin_trap();
38+
free(b->p);
4739
}
4840
}
4941

ctl/string.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ struct big_string
3838
size_t c : sizeof(size_t) * 8 - 1;
3939
size_t big : 1 /* = 1 */;
4040
#endif
41-
42-
~big_string() /* noexcept */;
4341
};
4442

4543
} // namespace __

0 commit comments

Comments
 (0)