[Lldb-commits] [PATCH] D107704: [LLDB][NFC] Simplify IOHandler's getLine to avoid strange casts and redundant checks

Alf via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Sat Aug 7 16:53:35 PDT 2021


gAlfonso-bit created this revision.
gAlfonso-bit requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

This is especially important at the end of the function, where originally there was a strange cast from optional to bool


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107704

Files:
  lldb/source/Core/IOHandler.cpp


Index: lldb/source/Core/IOHandler.cpp
===================================================================
--- lldb/source/Core/IOHandler.cpp
+++ lldb/source/Core/IOHandler.cpp
@@ -384,7 +384,7 @@
 
   if (!got_line && !in && m_input_sp) {
     // there is no FILE*, fall back on just reading bytes from the stream.
-    while (!got_line) {
+    do {
       size_t bytes_read = sizeof(buffer);
       Status error = m_input_sp->Read((void *)buffer, bytes_read);
       if (error.Success() && !bytes_read) {
@@ -395,12 +395,12 @@
         break;
       m_line_buffer += StringRef(buffer, bytes_read);
       got_line = SplitLine(m_line_buffer);
-    }
+    } while (!got_line);
   }
 
   if (!got_line && in) {
     m_editing = true;
-    while (!got_line) {
+    do {
       char *r = fgets(buffer, sizeof(buffer), in);
 #ifdef _WIN32
       // ReadFile on Windows is supposed to set ERROR_OPERATION_ABORTED
@@ -424,7 +424,7 @@
       }
       m_line_buffer += buffer;
       got_line = SplitLine(m_line_buffer);
-    }
+    } while (!got_line);
     m_editing = false;
   }
 
@@ -432,9 +432,10 @@
     line = got_line.getValue();
     if (m_data_recorder)
       m_data_recorder->Record(line, true);
+    return true;
   }
 
-  return (bool)got_line;
+  return false;
 }
 
 #if LLDB_ENABLE_LIBEDIT


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107704.364991.patch
Type: text/x-patch
Size: 1298 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20210807/92ad9d9f/attachment.bin>


More information about the lldb-commits mailing list