From 0db73b6a4c1bf600c5480710fdc799d430065123 Mon Sep 17 00:00:00 2001 From: Laurent Gomila Date: Mon, 17 Jun 2013 21:04:41 +0200 Subject: [PATCH] Minor improvements to sf::Packet operators (now using strlen and wcslen instead of explicit loops) (#118) --- src/SFML/Network/Packet.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/SFML/Network/Packet.cpp b/src/SFML/Network/Packet.cpp index baea2bed..053fa4eb 100644 --- a/src/SFML/Network/Packet.cpp +++ b/src/SFML/Network/Packet.cpp @@ -29,6 +29,7 @@ #include #include #include +#include namespace sf @@ -404,9 +405,7 @@ Packet& Packet::operator <<(double data) Packet& Packet::operator <<(const char* data) { // First insert string length - Uint32 length = 0; - for (const char* c = data; *c != '\0'; ++c) - ++length; + Uint32 length = std::strlen(data); *this << length; // Then insert characters @@ -425,9 +424,7 @@ Packet& Packet::operator <<(const std::string& data) // Then insert characters if (length > 0) - { append(data.c_str(), length * sizeof(std::string::value_type)); - } return *this; } @@ -437,9 +434,7 @@ Packet& Packet::operator <<(const std::string& data) Packet& Packet::operator <<(const wchar_t* data) { // First insert string length - Uint32 length = 0; - for (const wchar_t* c = data; *c != L'\0'; ++c) - ++length; + Uint32 length = std::wcslen(data); *this << length; // Then insert characters