Commit 9c224ea4 authored by Dominik Charousset's avatar Dominik Charousset

Use string_view for atom_from_string

parent c077fbc0
...@@ -40,7 +40,7 @@ std::string to_string(const atom_value& what); ...@@ -40,7 +40,7 @@ std::string to_string(const atom_value& what);
/// @relates atom_value /// @relates atom_value
atom_value to_lowercase(atom_value x); atom_value to_lowercase(atom_value x);
atom_value atom_from_string(const std::string& x); atom_value atom_from_string(string_view x);
/// Creates an atom from given string literal. /// Creates an atom from given string literal.
template <size_t Size> template <size_t Size>
......
...@@ -56,11 +56,11 @@ atom_value to_lowercase(atom_value x) { ...@@ -56,11 +56,11 @@ atom_value to_lowercase(atom_value x) {
return static_cast<atom_value>(detail::atom_val(buf.data())); return static_cast<atom_value>(detail::atom_val(buf.data()));
} }
atom_value atom_from_string(const std::string& x) { atom_value atom_from_string(string_view x) {
if (x.size() > 10) if (x.size() > 10)
return atom(""); return atom("");
atom_value_buf buf; atom_value_buf buf;
memcpy(buf.data(), x.c_str(), x.size()); memcpy(buf.data(), x.data(), x.size());
buf[x.size()] = '\0'; buf[x.size()] = '\0';
return static_cast<atom_value>(detail::atom_val(buf.data())); return static_cast<atom_value>(detail::atom_val(buf.data()));
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment