Skip to content

Commit

Permalink
Avoid unnecessary calls to unique_ptr::release()
Browse files Browse the repository at this point in the history
  • Loading branch information
aroffringa committed Feb 3, 2024
1 parent 8f8c0b9 commit 35d9df4
Show file tree
Hide file tree
Showing 25 changed files with 69 additions and 48 deletions.
3 changes: 2 additions & 1 deletion common/rpc/RpcServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <ola/network/SocketAddress.h>
#include <ola/network/TCPSocket.h>
#include <ola/rpc/RpcSessionHandler.h>
#include <utility>
#include "common/rpc/RpcChannel.h"
#include "common/rpc/RpcSession.h"

Expand Down Expand Up @@ -114,7 +115,7 @@ bool RpcServer::Init() {
return false;
}

m_accepting_socket.reset(accepting_socket.release());
m_accepting_socket = std::move(accepting_socket);
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion ola/StreamingClientTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ bool OlaServerThread::Setup() {
// pick an unused port
unique_ptr<OlaDaemon> olad(new OlaDaemon(ola_options, NULL));
if (olad->Init()) {
m_olad.reset(olad.release());
m_olad = std::move(olad);
return true;
} else {
return false;
Expand Down
5 changes: 3 additions & 2 deletions olad/OlaDaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <Shlobj.h>
#endif // _WIN32
#include <string>
#include <utility>

#include "ola/ExportMap.h"
#include "ola/Logging.h"
Expand Down Expand Up @@ -136,8 +137,8 @@ bool OlaDaemon::Init() {
bool ok = server->Init();
if (ok) {
// Set the members
m_preferences_factory.reset(preferences_factory.release());
m_server.reset(server.release());
m_preferences_factory = std::move(preferences_factory);
m_server = std::move(server);
} else {
STLDeleteElements(&m_plugin_loaders);
}
Expand Down
22 changes: 11 additions & 11 deletions olad/OlaServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ bool OlaServer::Init() {

// Initializing the web server causes a call to NewClient. We need to have
// the broker in place for the call, otherwise we'll segfault.
m_broker.reset(broker.release());
m_broker = std::move(broker);

#ifdef HAVE_LIBMICROHTTPD
if (m_options.http_enable) {
Expand All @@ -296,15 +296,15 @@ bool OlaServer::Init() {

// Ok, we've created and initialized everything correctly by this point. Now
// we save all the pointers and schedule the last of the callbacks.
m_device_manager.reset(device_manager.release());
m_discovery_agent.reset(discovery_agent.release());
m_plugin_adaptor.reset(plugin_adaptor.release());
m_plugin_manager.reset(plugin_manager.release());
m_port_broker.reset(port_broker.release());
m_port_manager.reset(port_manager.release());
m_rpc_server.reset(rpc_server.release());
m_service_impl.reset(service_impl.release());
m_universe_store.reset(universe_store.release());
m_device_manager = std::move(device_manager);
m_discovery_agent = std::move(discovery_agent);
m_plugin_adaptor = std::move(plugin_adaptor);
m_plugin_manager = std::move(plugin_manager);
m_port_broker = std::move(port_broker);
m_port_manager = std::move(port_manager);
m_rpc_server = std::move(rpc_server);
m_service_impl = std::move(service_impl);
m_universe_store = std::move(universe_store);

UpdatePidStore(pid_store.release());

Expand Down Expand Up @@ -434,7 +434,7 @@ bool OlaServer::StartHttpServer(ola::rpc::RpcServer *server,
httpd->Start();
// register the pipe descriptor as a client
InternalNewConnection(server, pipe_descriptor.release());
m_httpd.reset(httpd.release());
m_httpd = std::move(httpd);
return true;
} else {
pipe_descriptor->Close();
Expand Down
5 changes: 3 additions & 2 deletions plugins/kinet/KiNetNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <algorithm>
#include <memory>
#include <utility>

#include "ola/Constants.h"
#include "ola/Logging.h"
Expand Down Expand Up @@ -208,7 +209,7 @@ void KiNetNode::PopulatePacketHeader(uint16_t msg_type) {
* Setup the networking components.
*/
bool KiNetNode::InitNetwork() {
std::unique_ptr<ola::network::UDPSocketInterface> socket(m_socket.release());
std::unique_ptr<ola::network::UDPSocketInterface> socket(std::move(m_socket));

if (!socket.get())
socket.reset(new UDPSocket());
Expand All @@ -224,7 +225,7 @@ bool KiNetNode::InitNetwork() {

socket->SetOnData(NewCallback(this, &KiNetNode::SocketReady));
m_ss->AddReadDescriptor(socket.get());
m_socket.reset(socket.release());
m_socket = std::move(socket);
return true;
}
} // namespace kinet
Expand Down
5 changes: 3 additions & 2 deletions plugins/nanoleaf/NanoleafNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <algorithm>
#include <memory>
#include <utility>
#include <vector>

#include "ola/Constants.h"
Expand Down Expand Up @@ -157,7 +158,7 @@ void NanoleafNode::SocketReady() {
* Setup the networking components.
*/
bool NanoleafNode::InitNetwork() {
std::unique_ptr<ola::network::UDPSocketInterface> socket(m_socket.release());
std::unique_ptr<ola::network::UDPSocketInterface> socket(std::move(m_socket));

if (!socket.get()) {
socket.reset(new UDPSocket());
Expand All @@ -176,7 +177,7 @@ bool NanoleafNode::InitNetwork() {
// Do we need to call this if we don't bind?
socket->SetOnData(NewCallback(this, &NanoleafNode::SocketReady));
m_ss->AddReadDescriptor(socket.get());
m_socket.reset(socket.release());
m_socket = std::move(socket);
return true;
}
} // namespace nanoleaf
Expand Down
3 changes: 2 additions & 1 deletion plugins/openpixelcontrol/OPCServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "plugins/openpixelcontrol/OPCServer.h"

#include <string>
#include <utility>
#include "ola/Callback.h"
#include "ola/Logging.h"
#include "ola/base/Array.h"
Expand Down Expand Up @@ -88,7 +89,7 @@ bool OPCServer::Init() {
return false;
}
m_ss->AddReadDescriptor(listening_socket.get());
m_listening_socket.reset(listening_socket.release());
m_listening_socket = std::move(listening_socket);
return true;
}

Expand Down
3 changes: 2 additions & 1 deletion plugins/usbdmx/AVLdiyD512.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <unistd.h>
#include <string>
#include <utility>

#include "libs/usb/LibUsbAdaptor.h"
#include "ola/Logging.h"
Expand Down Expand Up @@ -105,7 +106,7 @@ bool SynchronousAVLdiyD512::Init() {
if (!sender->Start()) {
return false;
}
m_sender.reset(sender.release());
m_sender = std::move(sender);
return true;
}

Expand Down
3 changes: 2 additions & 1 deletion plugins/usbdmx/AnymauDMX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <unistd.h>
#include <string>
#include <utility>

#include "libs/usb/LibUsbAdaptor.h"
#include "ola/Logging.h"
Expand Down Expand Up @@ -105,7 +106,7 @@ bool SynchronousAnymauDMX::Init() {
if (!sender->Start()) {
return false;
}
m_sender.reset(sender.release());
m_sender = std::move(sender);
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/usbdmx/AsyncPluginImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ bool AsyncPluginImpl::Start() {
return false;
}

m_agent.reset(agent.release());
m_agent = std::move(agent);
return true;
}

Expand Down
5 changes: 3 additions & 2 deletions plugins/usbdmx/DMXCProjectsNodleU1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <unistd.h>
#include <algorithm>
#include <string>
#include <utility>

#include "ola/Logging.h"
#include "ola/Constants.h"
Expand Down Expand Up @@ -288,7 +289,7 @@ bool SynchronousDMXCProjectsNodleU1::Init() {
if (!sender->Start()) {
return false;
}
m_sender.reset(sender.release());
m_sender = std::move(sender);
}

if (m_mode & INPUT_ENABLE_MASK) { // input port active
Expand All @@ -298,7 +299,7 @@ bool SynchronousDMXCProjectsNodleU1::Init() {
if (!receiver->Start()) {
return false;
}
m_receiver.reset(receiver.release());
m_receiver = std::move(receiver);
}

return true;
Expand Down
3 changes: 2 additions & 1 deletion plugins/usbdmx/DMXCreator512Basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <unistd.h>
#include <string.h>
#include <string>
#include <utility>

#include "libs/usb/LibUsbAdaptor.h"
#include "ola/Logging.h"
Expand Down Expand Up @@ -172,7 +173,7 @@ bool SynchronousDMXCreator512Basic::Init() {
if (!sender->Start()) {
return false;
}
m_sender.reset(sender.release());
m_sender = std::move(sender);
return true;
}

Expand Down
3 changes: 2 additions & 1 deletion plugins/usbdmx/EurolitePro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <string.h>
#include <string>
#include <utility>

#include "libs/usb/LibUsbAdaptor.h"
#include "ola/Constants.h"
Expand Down Expand Up @@ -204,7 +205,7 @@ bool SynchronousEurolitePro::Init() {
if (!sender->Start()) {
return false;
}
m_sender.reset(sender.release());
m_sender = std::move(sender);
return true;
}

Expand Down
3 changes: 2 additions & 1 deletion plugins/usbdmx/ScanlimeFadecandy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <algorithm>
#include <limits>
#include <string>
#include <utility>

#include "libs/usb/LibUsbAdaptor.h"
#include "ola/base/Array.h"
Expand Down Expand Up @@ -271,7 +272,7 @@ bool SynchronousScanlimeFadecandy::Init() {
if (!sender->Start()) {
return false;
}
m_sender.reset(sender.release());
m_sender = std::move(sender);
return true;
}

Expand Down
7 changes: 4 additions & 3 deletions plugins/usbdmx/ShowJockeyDMXU1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
#include "plugins/usbdmx/ShowJockeyDMXU1.h"

#include <string.h>
#include <string>
#include <algorithm>
#include <string>
#include <utility>

#include "libs/usb/LibUsbAdaptor.h"
#include "ola/Constants.h"
Expand Down Expand Up @@ -248,7 +249,7 @@ bool SynchronousShowJockeyDMXU1::Init() {
return false;
}

m_sender.reset(sender.release());
m_sender = std::move(sender);
return true;
}

Expand Down Expand Up @@ -353,7 +354,7 @@ bool AsynchronousShowJockeyDMXU1::Init() {
endpoint,
max_packet_size,
usb_handle));
m_sender.reset(sender.release());
m_sender = std::move(sender);
return true;
}

Expand Down
3 changes: 2 additions & 1 deletion plugins/usbdmx/Sunlite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "plugins/usbdmx/Sunlite.h"

#include <string.h>
#include <utility>

#include "libs/usb/LibUsbAdaptor.h"
#include "ola/Constants.h"
Expand Down Expand Up @@ -154,7 +155,7 @@ bool SynchronousSunlite::Init() {
if (!sender->Start()) {
return false;
}
m_sender.reset(sender.release());
m_sender = std::move(sender);
return true;
}

Expand Down
3 changes: 2 additions & 1 deletion plugins/usbdmx/UsbDmxPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "plugins/usbdmx/UsbDmxPlugin.h"

#include <string>
#include <utility>

#include "ola/Logging.h"
#include "ola/base/Flags.h"
Expand Down Expand Up @@ -74,7 +75,7 @@ bool UsbDmxPlugin::StartHook() {
}

if (impl->Start()) {
m_impl.reset(impl.release());
m_impl = std::move(impl);
return true;
} else {
return false;
Expand Down
3 changes: 2 additions & 1 deletion plugins/usbdmx/VellemanK8062.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <unistd.h>
#include <algorithm>
#include <string>
#include <utility>

#include "libs/usb/LibUsbAdaptor.h"
#include "ola/Logging.h"
Expand Down Expand Up @@ -316,7 +317,7 @@ bool SynchronousVellemanK8062::Init() {
if (!sender->Start()) {
return false;
}
m_sender.reset(sender.release());
m_sender = std::move(sender);
return true;
}

Expand Down
5 changes: 3 additions & 2 deletions plugins/usbpro/ArduinoWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <algorithm>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "ola/io/ByteString.h"
#include "ola/Constants.h"
Expand Down Expand Up @@ -122,7 +123,7 @@ void ArduinoWidgetImpl::SendRDMRequest(RDMRequest *request_ptr,
}

m_rdm_request_callback = on_complete;
m_pending_request.reset(request.release());
m_pending_request = std::move(request);
if (SendMessage(RDM_REQUEST_LABEL, data.data(), data.size())) {
return;
}
Expand Down Expand Up @@ -161,7 +162,7 @@ void ArduinoWidgetImpl::HandleRDMResponse(const uint8_t *data,
ola::rdm::RDMCallback *callback = m_rdm_request_callback;
m_rdm_request_callback = NULL;
std::unique_ptr<const ola::rdm::RDMRequest> request(
m_pending_request.release());
std::move(m_pending_request));

if (length == 0) {
// invalid response
Expand Down
2 changes: 1 addition & 1 deletion plugins/usbpro/DmxTriWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ void DmxTriWidgetImpl::SendRDMRequest(RDMRequest *request_ptr,
}

// store pointers
m_pending_rdm_request.reset(request.release());
m_pending_rdm_request = std::move(request);
m_rdm_request_callback = on_complete;
MaybeSendNextRequest();
}
Expand Down
Loading

0 comments on commit 35d9df4

Please sign in to comment.