diff options
| author | Raphael Isemann <teemperor@gmail.com> | 2019-08-05 21:43:53 +0000 |
|---|---|---|
| committer | Raphael Isemann <teemperor@gmail.com> | 2019-08-05 21:43:53 +0000 |
| commit | 9de71690536d44d9a29a1fc1d9eea3bcb4eaf754 (patch) | |
| tree | 42d49f012e5ae5cf0650de764d398926869b9b93 | |
| parent | 5c3cdef84b82464756bb571c13c31cf7773860c3 (diff) | |
| download | bcm5719-llvm-9de71690536d44d9a29a1fc1d9eea3bcb4eaf754.tar.gz bcm5719-llvm-9de71690536d44d9a29a1fc1d9eea3bcb4eaf754.zip | |
[lldb][NFC] Document and refactor ClangPersistentVariables::RemovePersistentVariable
llvm-svn: 367936
| -rw-r--r-- | lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp index 38078fd7156..24dd705e37b 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp @@ -42,13 +42,25 @@ void ClangPersistentVariables::RemovePersistentVariable( lldb::ExpressionVariableSP variable) { RemoveVariable(variable); - const char *name = variable->GetName().AsCString(); + // Check if the removed variable was the last one that was created. If yes, + // reuse the variable id for the next variable. - if (*name != '$') + // Nothing to do if we have not assigned a variable id so far. + if (m_next_persistent_variable_id == 0) return; - name++; - if (strtoul(name, nullptr, 0) == m_next_persistent_variable_id - 1) + llvm::StringRef name = variable->GetName().GetStringRef(); + // Remove the prefix from the variable that only the indes is left. + if (!name.consume_front(GetPersistentVariablePrefix(false))) + return; + + // Check if the variable contained a variable id. + uint32_t variable_id; + if (name.getAsInteger(10, variable_id)) + return; + // If it's the most recent variable id that was assigned, make sure that this + // variable id will be used for the next persistent variable. + if (variable_id == m_next_persistent_variable_id - 1) m_next_persistent_variable_id--; } |

