[Lldb-commits] [lldb] 4679691 - [lldb/Core] Minor code cleanup in Editline.cpp (NFC)

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Thu Mar 5 16:15:44 PST 2020


Author: Shu Anzai
Date: 2020-03-05T16:15:26-08:00
New Revision: 467969161d94336cb0f091dff22bee403de71ffa

URL: https://github.com/llvm/llvm-project/commit/467969161d94336cb0f091dff22bee403de71ffa
DIFF: https://github.com/llvm/llvm-project/commit/467969161d94336cb0f091dff22bee403de71ffa.diff

LOG: [lldb/Core] Minor code cleanup in Editline.cpp (NFC)

Simplify the code a bit.

Differential revision: https://reviews.llvm.org/D75294

Added: 
    

Modified: 
    lldb/source/Host/common/Editline.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Host/common/Editline.cpp b/lldb/source/Host/common/Editline.cpp
index f73255d32240..60dc9ab0cabc 100644
--- a/lldb/source/Host/common/Editline.cpp
+++ b/lldb/source/Host/common/Editline.cpp
@@ -144,10 +144,10 @@ std::vector<EditLineStringType> SplitLines(const EditLineStringType &input) {
   while (start < input.length()) {
     size_t end = input.find('\n', start);
     if (end == std::string::npos) {
-      result.insert(result.end(), input.substr(start));
+      result.push_back(input.substr(start));
       break;
     }
-    result.insert(result.end(), input.substr(start, end - start));
+    result.push_back(input.substr(start, end - start));
     start = end + 1;
   }
   return result;
@@ -302,19 +302,16 @@ class EditlineHistory {
 // Editline private methods
 
 void Editline::SetBaseLineNumber(int line_number) {
-  std::stringstream line_number_stream;
-  line_number_stream << line_number;
   m_base_line_number = line_number;
   m_line_number_digits =
-      std::max(3, (int)line_number_stream.str().length() + 1);
+      std::max<int>(3, std::to_string(line_number).length() + 1);
 }
 
 std::string Editline::PromptForIndex(int line_index) {
   bool use_line_numbers = m_multiline_enabled && m_base_line_number > 0;
   std::string prompt = m_set_prompt;
-  if (use_line_numbers && prompt.length() == 0) {
+  if (use_line_numbers && prompt.length() == 0)
     prompt = ": ";
-  }
   std::string continuation_prompt = prompt;
   if (m_set_continuation_prompt.length() > 0) {
     continuation_prompt = m_set_continuation_prompt;
@@ -429,7 +426,7 @@ void Editline::DisplayInput(int firstIndex) {
 }
 
 int Editline::CountRowsForLine(const EditLineStringType &content) {
-  auto prompt =
+  std::string prompt =
       PromptForIndex(0); // Prompt width is constant during an edit session
   int line_length = (int)(content.length() + prompt.length());
   return (line_length / m_terminal_width) + 1;


        


More information about the lldb-commits mailing list