Don't reallocate MetaLexer on the heap for every line. Its a waste of time for 24 bytes that will be needed for every line anyway. Remove bufferEnd field as it was entirely unused.

This commit is contained in:
Frederich Munch 2016-07-02 23:32:46 -04:00 committed by sftnight
parent c54f88ce6a
commit a2fd30a8d5
4 changed files with 10 additions and 8 deletions

View File

@ -43,6 +43,11 @@ namespace cling {
: bufferStart(line.data()), curPos(line.data())
{ }
void MetaLexer::reset(llvm::StringRef line) {
bufferStart = line.data();
curPos = line.data();
}
void MetaLexer::Lex(Token& Tok) {
Tok.startToken(curPos);
char C = *curPos++;

View File

@ -82,10 +82,8 @@ namespace cling {
const char* bufferStart;
const char* curPos;
public:
MetaLexer(const char* bufStart)
: bufferStart(bufStart), curPos(bufStart)
{ }
MetaLexer(llvm::StringRef input);
void reset(llvm::StringRef Line);
void Lex(Token& Tok);
void LexAnyString(Token& Tok);

View File

@ -23,8 +23,7 @@
namespace cling {
MetaParser::MetaParser(MetaSema* Actions) {
m_Lexer.reset(0);
MetaParser::MetaParser(MetaSema* Actions) : m_Lexer("") {
m_Actions.reset(Actions);
const InvocationOptions& Opts = Actions->getInterpreter().getOptions();
MetaLexer metaSymbolLexer(Opts.MetaString);
@ -38,7 +37,7 @@ namespace cling {
}
void MetaParser::enterNewInputLine(llvm::StringRef Line) {
m_Lexer.reset(new MetaLexer(Line));
m_Lexer.reset(Line);
m_TokenCache.clear();
}
@ -86,7 +85,7 @@ namespace cling {
for (unsigned C = N+1 - m_TokenCache.size(); C > 0; --C) {
m_TokenCache.push_back(Token());
m_Lexer->Lex(m_TokenCache.back());
m_Lexer.Lex(m_TokenCache.back());
}
return m_TokenCache.back();
}

View File

@ -63,7 +63,7 @@ namespace cling {
//
class MetaParser {
private:
std::unique_ptr<MetaLexer> m_Lexer;
MetaLexer m_Lexer;
std::unique_ptr<MetaSema> m_Actions;
llvm::SmallVector<Token, 2> m_TokenCache;
llvm::SmallVector<Token, 4> m_MetaSymbolCache;