Skip to content

Commit

Permalink
src: define URLHost::Reset() function
Browse files Browse the repository at this point in the history
  • Loading branch information
prog1dev committed Jan 23, 2018
1 parent 63f78f5 commit bd831b4
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/node_url.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ class URLHost {
Value value_;
HostType type_ = HostType::H_FAILED;

inline void Reset() {
using string = std::string;
switch (type_) {
case HostType::H_DOMAIN: value_.domain.~string(); break;
case HostType::H_OPAQUE: value_.opaque.~string(); break;
default: break;
}
}

// Setting the string members of the union with = is brittle because
// it relies on them being initialized to a state that requires no
// destruction of old data.
Expand All @@ -112,12 +121,7 @@ class URLHost {
};

URLHost::~URLHost() {
using string = std::string;
switch (type_) {
case HostType::H_DOMAIN: value_.domain.~string(); break;
case HostType::H_OPAQUE: value_.opaque.~string(); break;
default: break;
}
Reset();
}

#define ARGS(XX) \
Expand Down

0 comments on commit bd831b4

Please sign in to comment.