From 530d84ae3b6782f45a1218e1b70fd787a714bada Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Tue, 21 Jan 2020 13:38:59 +0100 Subject: [PATCH] Make ConfigCompiler#m_LexBuffer a String ... to reduce malloc()s. --- lib/config/config_lexer.ll | 33 ++++++++++++++++----------------- lib/config/configcompiler.hpp | 3 ++- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/config/config_lexer.ll b/lib/config/config_lexer.ll index fcf603411..abfdaffb7 100644 --- a/lib/config/config_lexer.ll +++ b/lib/config/config_lexer.ll @@ -4,6 +4,7 @@ #include "config/configcompiler.hpp" #include "config/expression.hpp" #include "base/exception.hpp" +#include using namespace icinga; @@ -40,8 +41,7 @@ do { \ %% \" { - yyextra->m_LexBuffer.str(""); - yyextra->m_LexBuffer.clear(); + yyextra->m_LexBuffer.Clear(); yyextra->m_LocationBegin = *yylloc; @@ -54,7 +54,7 @@ do { \ yylloc->FirstLine = yyextra->m_LocationBegin.FirstLine; yylloc->FirstColumn = yyextra->m_LocationBegin.FirstColumn; - yylval->text = new String(yyextra->m_LexBuffer.str()); + yylval->text = new String(std::move(yyextra->m_LexBuffer)); return T_STRING; } @@ -74,7 +74,7 @@ do { \ BOOST_THROW_EXCEPTION(ScriptError("Constant is out of bounds: " + String(yytext), *yylloc)); } - yyextra->m_LexBuffer << static_cast(result); + yyextra->m_LexBuffer += static_cast(result); } \\[0-9]+ { @@ -83,14 +83,14 @@ do { \ */ BOOST_THROW_EXCEPTION(ScriptError("Bad escape sequence found: " + String(yytext), *yylloc)); } -\\n { yyextra->m_LexBuffer << "\n"; } -\\\\ { yyextra->m_LexBuffer << "\\"; } -\\\" { yyextra->m_LexBuffer << "\""; } -\\t { yyextra->m_LexBuffer << "\t"; } -\\r { yyextra->m_LexBuffer << "\r"; } -\\b { yyextra->m_LexBuffer << "\b"; } -\\f { yyextra->m_LexBuffer << "\f"; } -\\\n { yyextra->m_LexBuffer << yytext[1]; } +\\n { yyextra->m_LexBuffer += '\n'; } +\\\\ { yyextra->m_LexBuffer += '\\'; } +\\\" { yyextra->m_LexBuffer += '"'; } +\\t { yyextra->m_LexBuffer += '\t'; } +\\r { yyextra->m_LexBuffer += '\r'; } +\\b { yyextra->m_LexBuffer += '\b'; } +\\f { yyextra->m_LexBuffer += '\f'; } +\\\n { yyextra->m_LexBuffer += yytext[1]; } \\. { BOOST_THROW_EXCEPTION(ScriptError("Bad escape sequence found: " + String(yytext), *yylloc)); } @@ -99,7 +99,7 @@ do { \ char *yptr = yytext; while (*yptr) - yyextra->m_LexBuffer << *yptr++; + yyextra->m_LexBuffer += *yptr++; } <> { @@ -107,8 +107,7 @@ do { \ } \{\{\{ { - yyextra->m_LexBuffer.str(""); - yyextra->m_LexBuffer.clear(); + yyextra->m_LexBuffer.Clear(); yyextra->m_LocationBegin = *yylloc; @@ -125,12 +124,12 @@ do { \ yylloc->FirstLine = yyextra->m_LocationBegin.FirstLine; yylloc->FirstColumn = yyextra->m_LocationBegin.FirstColumn; - yylval->text = new String(yyextra->m_LexBuffer.str()); + yylval->text = new String(std::move(yyextra->m_LexBuffer)); return T_STRING; } -(.|\n) { yyextra->m_LexBuffer << yytext[0]; } +(.|\n) { yyextra->m_LexBuffer += yytext[0]; } { "/*" BEGIN(C_COMMENT); diff --git a/lib/config/configcompiler.hpp b/lib/config/configcompiler.hpp index 65acf8ea2..961e3d238 100644 --- a/lib/config/configcompiler.hpp +++ b/lib/config/configcompiler.hpp @@ -9,6 +9,7 @@ #include "base/registry.hpp" #include "base/initialize.hpp" #include "base/singleton.hpp" +#include "base/string.hpp" #include #include #include @@ -139,7 +140,7 @@ public: bool m_Eof; int m_OpenBraces; - std::ostringstream m_LexBuffer; + String m_LexBuffer; CompilerDebugInfo m_LocationBegin; std::stack m_IgnoreNewlines;