Minor improvements to sf::Packet operators (now using strlen and wcslen instead of explicit loops) (#118)

This commit is contained in:
Laurent Gomila 2013-06-17 21:04:41 +02:00
parent 5d377fdb38
commit 0db73b6a4c

View File

@ -29,6 +29,7 @@
#include <SFML/Network/SocketImpl.hpp>
#include <SFML/System/String.hpp>
#include <cstring>
#include <cwchar>
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