From a82d7ea5fa34ec92407606b994847a76f942016a Mon Sep 17 00:00:00 2001 From: Mathieu Carbou Date: Wed, 12 Nov 2025 14:41:32 +0100 Subject: [PATCH] move semantic --- src/WebSerial.cpp | 12 +++++++----- src/WebSerial.h | 3 +-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/WebSerial.cpp b/src/WebSerial.cpp index dda2595..73f11f2 100644 --- a/src/WebSerial.cpp +++ b/src/WebSerial.cpp @@ -4,6 +4,8 @@ #include +#include + // DO NOT change magic bytes #define WSL_MAGIC_BYTE_1 0xAB #define WSL_MAGIC_BYTE_2 0xCD @@ -38,9 +40,9 @@ static const size_t WSL_HEAD_LEN = sizeof(WSL_HEAD) / sizeof(WSL_HEAD[0]); static const size_t WSL_MSG_SIZE_LEN = sizeof(uint16_t); -void WebSerialClass::setAuthentication(const String& username, const String& password){ - _username = username; - _password = password; +void WebSerialClass::setAuthentication(String username, String password){ + _username = std::move(username); + _password = std::move(password); _authenticate = !_username.isEmpty() && !_password.isEmpty(); if (_ws != nullptr) { _ws->setAuthentication(_username.c_str(), _password.c_str()); @@ -99,11 +101,11 @@ void WebSerialClass::begin(AsyncWebServer *server, const char* url) { // onMessage Callback Handler void WebSerialClass::onMessage(WSLMessageHandler recv) { - _recv = recv; + _recv = std::move(recv); } void WebSerialClass::onMessage(WSLStringMessageHandler callback) { - _recvString = callback; + _recvString = std::move(callback); _recv = [&](uint8_t *data, size_t len) { if(data && len) { String msg; diff --git a/src/WebSerial.h b/src/WebSerial.h index eb7bf9f..8fd54aa 100644 --- a/src/WebSerial.h +++ b/src/WebSerial.h @@ -102,8 +102,7 @@ typedef std::function WSLStringMessageHandler; class WebSerialClass : public Print { public: void begin(AsyncWebServer *server, const char* url = "/webserial"); - inline void setAuthentication(const char* username, const char* password) { setAuthentication(String(username), String(password)); } - void setAuthentication(const String& username, const String& password); + void setAuthentication(String username, String password); void onMessage(WSLMessageHandler recv); void onMessage(WSLStringMessageHandler recv); bool getConnectionCount();