Sfoglia il codice sorgente

udp/client: Take std::function by const reference with TestCommunication()

Avoids redundant copies.
Lioncash 5 anni fa
parent
commit
36cfb234d5
2 ha cambiato i file con 5 aggiunte e 5 eliminazioni
  1. 3 3
      src/input_common/udp/client.cpp
  2. 2 2
      src/input_common/udp/client.h

+ 3 - 3
src/input_common/udp/client.cpp

@@ -333,15 +333,15 @@ const std::array<Common::SPSCQueue<UDPPadStatus>, 4>& Client::GetPadQueue() cons
 }
 
 void TestCommunication(const std::string& host, u16 port, std::size_t pad_index, u32 client_id,
-                       std::function<void()> success_callback,
-                       std::function<void()> failure_callback) {
+                       const std::function<void()>& success_callback,
+                       const std::function<void()>& failure_callback) {
     std::thread([=] {
         Common::Event success_event;
         SocketCallback callback{[](Response::Version version) {}, [](Response::PortInfo info) {},
                                 [&](Response::PadData data) { success_event.Set(); }};
         Socket socket{host, port, pad_index, client_id, std::move(callback)};
         std::thread worker_thread{SocketLoop, &socket};
-        bool result = success_event.WaitFor(std::chrono::seconds(8));
+        const bool result = success_event.WaitFor(std::chrono::seconds(8));
         socket.Stop();
         worker_thread.join();
         if (result) {

+ 2 - 2
src/input_common/udp/client.h

@@ -150,7 +150,7 @@ private:
 };
 
 void TestCommunication(const std::string& host, u16 port, std::size_t pad_index, u32 client_id,
-                       std::function<void()> success_callback,
-                       std::function<void()> failure_callback);
+                       const std::function<void()>& success_callback,
+                       const std::function<void()>& failure_callback);
 
 } // namespace InputCommon::CemuhookUDP