Skip to content

Commit

Permalink
address feedback again
Browse files Browse the repository at this point in the history
Signed-off-by: Byoungro So <byoungro.so@intel.com>
  • Loading branch information
bso-intel committed Feb 5, 2024
1 parent 67ecf71 commit e385649
Showing 1 changed file with 10 additions and 21 deletions.
31 changes: 10 additions & 21 deletions sycl/include/sycl/detail/string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,10 @@ class string {
char *str = nullptr;

public:
string() noexcept {
str = new char[1];
*str = 0;
}
string() noexcept = default;
~string() { delete[] str; }

string(const std::string_view &strn) noexcept {
string(const std::string_view &strn) {
size_t len = strn.length();
str = new char[len + 1];
strn.copy(str, len);
Expand All @@ -40,34 +37,26 @@ class string {
}

string(string &&other) noexcept { swap(*this, other); }
string(const string &other) noexcept {
size_t len = strlen(other.str);
str = new char[len + 1];
strcpy(str, other.str);
string(const string &other) {
if (other.str == nullptr)
return;
*this = string{other.str};
}

string &operator=(string &&other) noexcept {
swap(*this, other);
return *this;
}
string &operator=(const string &other) noexcept {
size_t len = strlen(other.str);
delete[] str;
str = new char[len + 1];
strcpy(str, other.str);
string &operator=(const string &other) {
*this = string{other.str};
return *this;
}

string &operator=(const std::string_view &strn) noexcept {
int len = strn.length();
delete[] str;
str = new char[len + 1];
strn.copy(str, len);
str[len] = 0;
string &operator=(const std::string_view &strn) {
*this = string{strn};
return *this;
}

const char *c_str() noexcept { return str; }
const char *c_str() const noexcept { return str; }

friend bool operator==(const string &lhs,
Expand Down

0 comments on commit e385649

Please sign in to comment.