Use std::string_view and fmtlib across all libraries (#3402)

- Twine, StringRef, Format, and NativeFormatting have been removed
- Logging now uses fmtlib style formatting
- Nearly all uses of wpi::outs/errs have been replaced with fmt::print() or
std::puts()/std::fputs() (for unformatted strings).
- A wpi/fmt/raw_ostream.h header has been added to enable
fmt::print() with wpi::raw_ostream
This commit is contained in:
Peter Johnson
2021-06-06 16:13:58 -07:00
committed by GitHub
parent 4f1cecb8e7
commit b2c3b2dd8e
441 changed files with 5061 additions and 9749 deletions

View File

@@ -4,10 +4,9 @@
#include "wpi/PortForwarder.h"
#include "fmt/format.h"
#include "wpi/DenseMap.h"
#include "wpi/EventLoopRunner.h"
#include "wpi/SmallString.h"
#include "wpi/raw_ostream.h"
#include "wpi/uv/GetAddrInfo.h"
#include "wpi/uv/Tcp.h"
#include "wpi/uv/Timer.h"
@@ -45,7 +44,7 @@ static void CopyStream(uv::Stream& in, std::weak_ptr<uv::Stream> outWeak) {
});
}
void PortForwarder::Add(unsigned int port, const Twine& remoteHost,
void PortForwarder::Add(unsigned int port, std::string_view remoteHost,
unsigned int remotePort) {
m_impl->runner.ExecSync([&](uv::Loop& loop) {
auto server = uv::Tcp::Create(loop);
@@ -55,7 +54,7 @@ void PortForwarder::Add(unsigned int port, const Twine& remoteHost,
// when we get a connection, accept it
server->connection.connect([serverPtr = server.get(),
host = remoteHost.str(), remotePort] {
host = std::string{remoteHost}, remotePort] {
auto& loop = serverPtr->GetLoopRef();
auto client = serverPtr->Accept();
if (!client) {
@@ -80,10 +79,6 @@ void PortForwarder::Add(unsigned int port, const Twine& remoteHost,
}
});
// convert port to string
SmallString<16> remotePortStr;
raw_svector_ostream(remotePortStr) << remotePort;
// resolve address
uv::GetAddrInfo(
loop,
@@ -125,7 +120,7 @@ void PortForwarder::Add(unsigned int port, const Twine& remoteHost,
CopyStream(*remotePtr, clientWeak);
});
},
host, remotePortStr);
host, fmt::to_string(remotePort));
// time out for connection
uv::Timer::SingleShot(loop, uv::Timer::Time{500},