JDevlieghere added a comment.

If debugserver linked against libSupport we could have saved the additional 
copy altogether by using `llvm::raw_string_ostream`:

  std::string str;
  llvm::raw_string_ostream stream(str);
  stream.str() // Flushes and returns a reference to the stack allocated str

Barring that, I wonder if if a little wrapper around `std::ostringstream` could 
improve readability and avoid bugs where someone forgets to call 
`stream.str("")`.

  class AggressiveStream {
  public:
    AggressiveStream() : m_stream(std::make_unique<std::ostringstream>()) {}
  
    std::ostringstream &operator*() {
      assert(m_stream && "cannot use stream after having called str()");
      return *m_stream;
    }
  
    std::string str() {
      std::string s = m_stream->str();
      m_stream.reset();
      return std::move(s);
    }
  
  private:
    std::unique_ptr<std::ostringstream> m_stream;
  };

WDYT?



================
Comment at: lldb/tools/debugserver/source/RNBRemote.cpp:588
+  stream.str(std::string());
+  stream.clear();
   return SendPacket(payload);
----------------
`clear` doesn't do what you think it does, it modifies the state flag which 
isn't relevant here.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122848/new/

https://reviews.llvm.org/D122848

_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to