From 00895a57893f1680c30ec0bc3ad23ca8b3c2d159 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 18 Sep 2021 12:48:34 +0200 Subject: [PATCH] LibWebSocket: Fix a handful of clang-tidy warnings in WebSocket.{cpp,h} --- Userland/Libraries/LibWebSocket/WebSocket.cpp | 23 ++++++++----------- Userland/Libraries/LibWebSocket/WebSocket.h | 4 ++-- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/Userland/Libraries/LibWebSocket/WebSocket.cpp b/Userland/Libraries/LibWebSocket/WebSocket.cpp index e4a14f4f40..47da68f07a 100644 --- a/Userland/Libraries/LibWebSocket/WebSocket.cpp +++ b/Userland/Libraries/LibWebSocket/WebSocket.cpp @@ -5,13 +5,11 @@ */ #include -#include #include #include #include #include #include -#include #include namespace WebSocket { @@ -21,11 +19,11 @@ namespace WebSocket { NonnullRefPtr WebSocket::create(ConnectionInfo connection) { - return adopt_ref(*new WebSocket(connection)); + return adopt_ref(*new WebSocket(move(connection))); } WebSocket::WebSocket(ConnectionInfo connection) - : m_connection(connection) + : m_connection(move(connection)) { } @@ -81,7 +79,7 @@ ReadyState WebSocket::ready_state() } } -void WebSocket::send(Message message) +void WebSocket::send(Message const& message) { // Calling send on a socket that is not opened is not allowed VERIFY(m_state == WebSocket::InternalState::Open); @@ -92,7 +90,7 @@ void WebSocket::send(Message message) send_frame(WebSocket::OpCode::Binary, message.data(), true); } -void WebSocket::close(u16 code, String message) +void WebSocket::close(u16 code, String const& message) { // Calling close on a socket that is not opened is not allowed VERIFY(m_state == WebSocket::InternalState::Open); @@ -320,10 +318,10 @@ void WebSocket::read_server_handshake() if (header_name.equals_ignoring_case("Sec-WebSocket-Extensions")) { // 5. |Sec-WebSocket-Extensions| should not contain an extension that doesn't appear in m_connection->extensions() auto server_extensions = parts[1].split(','); - for (auto extension : server_extensions) { + for (auto const& extension : server_extensions) { auto trimmed_extension = extension.trim_whitespace(); bool found_extension = false; - for (auto supported_extension : m_connection.extensions()) { + for (auto const& supported_extension : m_connection.extensions()) { if (trimmed_extension.equals_ignoring_case(supported_extension)) { found_extension = true; } @@ -340,10 +338,10 @@ void WebSocket::read_server_handshake() if (header_name.equals_ignoring_case("Sec-WebSocket-Protocol")) { // 6. |Sec-WebSocket-Protocol| should not contain an extension that doesn't appear in m_connection->protocols() auto server_protocols = parts[1].split(','); - for (auto protocol : server_protocols) { + for (auto const& protocol : server_protocols) { auto trimmed_protocol = protocol.trim_whitespace(); bool found_protocol = false; - for (auto supported_protocol : m_connection.protocols()) { + for (auto const& supported_protocol : m_connection.protocols()) { if (trimmed_protocol.equals_ignoring_case(supported_protocol)) { found_protocol = true; } @@ -470,7 +468,6 @@ void WebSocket::read_frame() if (op_code == WebSocket::OpCode::Continuation) { // FIXME: Support fragmented frames TODO(); - return; } if (op_code == WebSocket::OpCode::Text) { notify_message(Message(payload, true)); @@ -587,7 +584,7 @@ void WebSocket::notify_close(u16 code, String reason, bool was_clean) { if (!on_close) return; - on_close(code, reason, was_clean); + on_close(code, move(reason), was_clean); } void WebSocket::notify_error(WebSocket::Error error) @@ -601,7 +598,7 @@ void WebSocket::notify_message(Message message) { if (!on_message) return; - on_message(message); + on_message(move(message)); } } diff --git a/Userland/Libraries/LibWebSocket/WebSocket.h b/Userland/Libraries/LibWebSocket/WebSocket.h index 998372022e..9fd18893c2 100644 --- a/Userland/Libraries/LibWebSocket/WebSocket.h +++ b/Userland/Libraries/LibWebSocket/WebSocket.h @@ -35,10 +35,10 @@ public: void start(); // This can only be used if the `ready_state` is `ReadyState::Open` - void send(Message); + void send(Message const&); // This can only be used if the `ready_state` is `ReadyState::Open` - void close(u16 code = 1005, String reason = {}); + void close(u16 code = 1005, String const& reason = {}); Function on_open; Function on_close;