Micro optimize command parsing by avoiding utf8 decoding
Balanced quoted parsing does not need to decode utf8, neither does unquoted word parsing. This improves startup time a bit, helping for issue #2152
This commit is contained in:
parent
918fe6ddd8
commit
a5f53dccb7
|
@ -105,8 +105,8 @@ QuotedResult parse_quoted(Reader& reader, Codepoint delimiter)
|
||||||
return {str, false};
|
return {str, false};
|
||||||
}
|
}
|
||||||
|
|
||||||
QuotedResult parse_quoted_balanced(Reader& reader, Codepoint opening_delimiter,
|
QuotedResult parse_quoted_balanced(Reader& reader, char opening_delimiter,
|
||||||
Codepoint closing_delimiter)
|
char closing_delimiter)
|
||||||
{
|
{
|
||||||
kak_assert(utf8::codepoint(utf8::previous(reader.pos, reader.str.begin()),
|
kak_assert(utf8::codepoint(utf8::previous(reader.pos, reader.str.begin()),
|
||||||
reader.str.end()) == opening_delimiter);
|
reader.str.end()) == opening_delimiter);
|
||||||
|
@ -114,16 +114,16 @@ QuotedResult parse_quoted_balanced(Reader& reader, Codepoint opening_delimiter,
|
||||||
auto start = reader.pos;
|
auto start = reader.pos;
|
||||||
while (reader)
|
while (reader)
|
||||||
{
|
{
|
||||||
const Codepoint c = *reader;
|
const char c = *reader.pos;
|
||||||
if (c == opening_delimiter)
|
if (c == opening_delimiter)
|
||||||
++level;
|
++level;
|
||||||
else if (c == closing_delimiter and level-- == 0)
|
else if (c == closing_delimiter and level-- == 0)
|
||||||
{
|
{
|
||||||
auto content = reader.substr_from(start);
|
auto content = reader.substr_from(start);
|
||||||
++reader;
|
++reader.pos;
|
||||||
return {content.str(), true};
|
return {content.str(), true};
|
||||||
}
|
}
|
||||||
++reader;
|
++reader.pos;
|
||||||
}
|
}
|
||||||
return {reader.substr_from(start).str(), false};
|
return {reader.substr_from(start).str(), false};
|
||||||
}
|
}
|
||||||
|
@ -132,15 +132,14 @@ String parse_unquoted(Reader& reader)
|
||||||
{
|
{
|
||||||
auto beg = reader.pos;
|
auto beg = reader.pos;
|
||||||
String str;
|
String str;
|
||||||
bool was_antislash = false;
|
|
||||||
|
|
||||||
while (reader)
|
while (reader)
|
||||||
{
|
{
|
||||||
const Codepoint c = *reader;
|
const char c = *reader.pos;
|
||||||
if (is_command_separator(c) or is_horizontal_blank(c))
|
if (is_command_separator(c) or is_horizontal_blank(c))
|
||||||
{
|
{
|
||||||
str += reader.substr_from(beg);
|
str += reader.substr_from(beg);
|
||||||
if (was_antislash)
|
if (reader.pos != reader.str.begin() and *(reader.pos - 1) == '\\')
|
||||||
{
|
{
|
||||||
str.back() = c;
|
str.back() = c;
|
||||||
beg = reader.pos+1;
|
beg = reader.pos+1;
|
||||||
|
@ -148,8 +147,7 @@ String parse_unquoted(Reader& reader)
|
||||||
else
|
else
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
was_antislash = c == '\\';
|
++reader.pos;
|
||||||
++reader;
|
|
||||||
}
|
}
|
||||||
if (beg < reader.str.end())
|
if (beg < reader.str.end())
|
||||||
str += reader.substr_from(beg);
|
str += reader.substr_from(beg);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user