Skip to content

Commit bd831b4

Browse files
committed
src: define URLHost::Reset() function
Fixes: nodejs#18302
1 parent 63f78f5 commit bd831b4

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/node_url.cc

+10-6
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,15 @@ class URLHost {
9292
Value value_;
9393
HostType type_ = HostType::H_FAILED;
9494

95+
inline void Reset() {
96+
using string = std::string;
97+
switch (type_) {
98+
case HostType::H_DOMAIN: value_.domain.~string(); break;
99+
case HostType::H_OPAQUE: value_.opaque.~string(); break;
100+
default: break;
101+
}
102+
}
103+
95104
// Setting the string members of the union with = is brittle because
96105
// it relies on them being initialized to a state that requires no
97106
// destruction of old data.
@@ -112,12 +121,7 @@ class URLHost {
112121
};
113122

114123
URLHost::~URLHost() {
115-
using string = std::string;
116-
switch (type_) {
117-
case HostType::H_DOMAIN: value_.domain.~string(); break;
118-
case HostType::H_OPAQUE: value_.opaque.~string(); break;
119-
default: break;
120-
}
124+
Reset();
121125
}
122126

123127
#define ARGS(XX) \

0 commit comments

Comments
 (0)