Optimize InputValidator to avoid unnecessary copy when retrieving the input directly before a reset, and to release memory when reset.

This commit is contained in:
Frederich Munch 2016-07-11 21:32:59 -04:00 committed by sftnight
parent 91c925632c
commit 178c33e251
3 changed files with 13 additions and 12 deletions

View File

@ -213,8 +213,13 @@ namespace cling {
return Res;
}
void InputValidator::reset() {
m_Input = "";
m_ParenStack.clear();
void InputValidator::reset(std::string* input) {
if (input) {
assert(input->empty() && "InputValidator::reset got non empty argument");
input->swap(m_Input);
} else
std::string().swap(m_Input);
std::deque<int>().swap(m_ParenStack);
}
} // end namespace cling

View File

@ -54,12 +54,6 @@ namespace cling {
///
ValidationResult validate(llvm::StringRef line);
///\returns Reference to the collected input.
///
std::string& getInput() {
return m_Input;
}
///\brief Retrieves the number of spaces that the next input line should be
/// indented.
///
@ -67,7 +61,9 @@ namespace cling {
///\brief Resets the collected input and its corresponding brace stack.
///
void reset();
///\param[in] input - Grab the collected input before reseting.
///
void reset(std::string* input = nullptr);
///\brief Return whether we are inside a mult-line comment
///

View File

@ -169,8 +169,8 @@ namespace cling {
}
// We have a complete statement, compile and execute it.
std::string input = m_InputValidator->getInput();
m_InputValidator->reset();
std::string input;
m_InputValidator->reset(&input);
// if (m_Options.RawInput)
// compResLocal = m_Interp.declare(input);
// else