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:
parent
91c925632c
commit
178c33e251
@ -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
|
||||
|
@ -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
|
||||
///
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user