mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-24 01:31:46 +00:00
[wpiutil] uv: use move for std::function (#3653)
Also use function_ref for Loop::Walk().
This commit is contained in:
@@ -38,7 +38,7 @@ class AsyncFunction<R(T...)> final
|
||||
public:
|
||||
AsyncFunction(const std::shared_ptr<Loop>& loop,
|
||||
std::function<void(promise<R>, T...)> func, const private_init&)
|
||||
: wakeup{func}, m_loop{loop} {}
|
||||
: wakeup{std::move(func)}, m_loop{loop} {}
|
||||
~AsyncFunction() noexcept override {
|
||||
if (auto loop = m_loop.lock()) {
|
||||
this->Close();
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
|
||||
#include "wpi/Signal.h"
|
||||
#include "wpi/uv/Request.h"
|
||||
@@ -110,7 +111,7 @@ inline void GetAddrInfo(const std::shared_ptr<Loop>& loop,
|
||||
std::function<void(const addrinfo&)> callback,
|
||||
std::string_view node, std::string_view service = {},
|
||||
const addrinfo* hints = nullptr) {
|
||||
GetAddrInfo(*loop, callback, node, service, hints);
|
||||
GetAddrInfo(*loop, std::move(callback), node, service, hints);
|
||||
}
|
||||
|
||||
} // namespace wpi::uv
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
|
||||
#include "wpi/Signal.h"
|
||||
#include "wpi/uv/Request.h"
|
||||
@@ -90,7 +91,7 @@ void GetNameInfo(Loop& loop,
|
||||
inline void GetNameInfo(const std::shared_ptr<Loop>& loop,
|
||||
std::function<void(const char*, const char*)> callback,
|
||||
const sockaddr& addr, int flags = 0) {
|
||||
GetNameInfo(*loop, callback, addr, flags);
|
||||
GetNameInfo(*loop, std::move(callback), addr, flags);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -154,7 +155,7 @@ inline void GetNameInfo4(const std::shared_ptr<Loop>& loop,
|
||||
std::function<void(const char*, const char*)> callback,
|
||||
std::string_view ip, unsigned int port,
|
||||
int flags = 0) {
|
||||
return GetNameInfo4(*loop, callback, ip, port, flags);
|
||||
return GetNameInfo4(*loop, std::move(callback), ip, port, flags);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -219,7 +220,7 @@ inline void GetNameInfo6(const std::shared_ptr<Loop>& loop,
|
||||
std::function<void(const char*, const char*)> callback,
|
||||
std::string_view ip, unsigned int port,
|
||||
int flags = 0) {
|
||||
return GetNameInfo6(*loop, callback, ip, port, flags);
|
||||
return GetNameInfo6(*loop, std::move(callback), ip, port, flags);
|
||||
}
|
||||
|
||||
} // namespace wpi::uv
|
||||
|
||||
@@ -191,8 +191,8 @@ class Handle : public std::enable_shared_from_this<Handle> {
|
||||
*/
|
||||
void SetBufferAllocator(std::function<Buffer(size_t)> alloc,
|
||||
std::function<void(Buffer&)> dealloc) {
|
||||
m_allocBuf = alloc;
|
||||
m_freeBuf = dealloc;
|
||||
m_allocBuf = std::move(alloc);
|
||||
m_freeBuf = std::move(dealloc);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <utility>
|
||||
|
||||
#include "wpi/Signal.h"
|
||||
#include "wpi/function_ref.h"
|
||||
#include "wpi/uv/Error.h"
|
||||
|
||||
namespace wpi::uv {
|
||||
@@ -171,7 +172,7 @@ class Loop final : public std::enable_shared_from_this<Loop> {
|
||||
*
|
||||
* @param callback A function to be invoked once for each active handle.
|
||||
*/
|
||||
void Walk(std::function<void(Handle&)> callback);
|
||||
void Walk(function_ref<void(Handle&)> callback);
|
||||
|
||||
/**
|
||||
* Reinitialize any kernel state necessary in the child process after
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <functional>
|
||||
#include <initializer_list>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include "wpi/Signal.h"
|
||||
#include "wpi/span.h"
|
||||
@@ -180,7 +181,7 @@ class Stream : public Handle {
|
||||
*/
|
||||
void Write(std::initializer_list<Buffer> bufs,
|
||||
std::function<void(span<Buffer>, Error)> callback) {
|
||||
Write({bufs.begin(), bufs.end()}, callback);
|
||||
Write({bufs.begin(), bufs.end()}, std::move(callback));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
|
||||
#include "wpi/uv/NetworkStream.h"
|
||||
|
||||
@@ -258,11 +259,11 @@ class Tcp final : public NetworkStreamImpl<Tcp, uv_tcp_t> {
|
||||
void Connect(const sockaddr& addr, std::function<void()> callback);
|
||||
|
||||
void Connect(const sockaddr_in& addr, std::function<void()> callback) {
|
||||
Connect(reinterpret_cast<const sockaddr&>(addr), callback);
|
||||
Connect(reinterpret_cast<const sockaddr&>(addr), std::move(callback));
|
||||
}
|
||||
|
||||
void Connect(const sockaddr_in6& addr, std::function<void()> callback) {
|
||||
Connect(reinterpret_cast<const sockaddr&>(addr), callback);
|
||||
Connect(reinterpret_cast<const sockaddr&>(addr), std::move(callback));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <chrono>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include "wpi/Signal.h"
|
||||
#include "wpi/uv/Handle.h"
|
||||
@@ -65,7 +66,7 @@ class Timer final : public HandleImpl<Timer, uv_timer_t> {
|
||||
*/
|
||||
static void SingleShot(const std::shared_ptr<Loop>& loop, Time timeout,
|
||||
std::function<void()> func) {
|
||||
return SingleShot(*loop, timeout, func);
|
||||
return SingleShot(*loop, timeout, std::move(func));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
|
||||
#include "wpi/Signal.h"
|
||||
#include "wpi/span.h"
|
||||
@@ -274,12 +275,12 @@ class Udp final : public HandleImpl<Udp, uv_udp_t> {
|
||||
|
||||
void Send(const sockaddr_in& addr, span<const Buffer> bufs,
|
||||
std::function<void(span<Buffer>, Error)> callback) {
|
||||
Send(reinterpret_cast<const sockaddr&>(addr), bufs, callback);
|
||||
Send(reinterpret_cast<const sockaddr&>(addr), bufs, std::move(callback));
|
||||
}
|
||||
|
||||
void Send(const sockaddr_in6& addr, span<const Buffer> bufs,
|
||||
std::function<void(span<Buffer>, Error)> callback) {
|
||||
Send(reinterpret_cast<const sockaddr&>(addr), bufs, callback);
|
||||
Send(reinterpret_cast<const sockaddr&>(addr), bufs, std::move(callback));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include "wpi/Signal.h"
|
||||
#include "wpi/uv/Request.h"
|
||||
@@ -84,7 +85,7 @@ void QueueWork(Loop& loop, std::function<void()> work,
|
||||
inline void QueueWork(const std::shared_ptr<Loop>& loop,
|
||||
std::function<void()> work,
|
||||
std::function<void()> afterWork) {
|
||||
QueueWork(*loop, work, afterWork);
|
||||
QueueWork(*loop, std::move(work), std::move(afterWork));
|
||||
}
|
||||
|
||||
} // namespace wpi::uv
|
||||
|
||||
Reference in New Issue
Block a user