Avoid instanciation of a String object everytime the parse_color

function is called.
This commit is contained in:
Frank LENORMAND 2015-12-12 12:00:52 +03:00
parent 49a5bbf3ca
commit bd56ed5fad

View File

@ -9,15 +9,15 @@ namespace Kakoune
static Face parse_face(StringView facedesc)
{
const String invalid_face_error = "invalid face description, expected <fg>[,<bg>][+<attr>]";
constexpr StringView invalid_face_error = "invalid face description, expected <fg>[,<bg>][+<attr>]";
auto bg_it = find(facedesc, ',');
auto attr_it = find(facedesc, '+');
if (bg_it != facedesc.end()
and (attr_it < bg_it or (bg_it + 1) == facedesc.end()))
throw runtime_error(invalid_face_error);
throw runtime_error(invalid_face_error.str());
if (attr_it != facedesc.end()
and (attr_it + 1) == facedesc.end())
throw runtime_error(invalid_face_error);
throw runtime_error(invalid_face_error.str());
Face res;
res.fg = attr_it != facedesc.begin() ?
str_to_color({facedesc.begin(), std::min(attr_it, bg_it)}) : Color::Default;