Skip to content

Commit

Permalink
Remove unnecessary sf::String construction
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisThrasher committed Dec 24, 2024
1 parent 589b86d commit 0bdbb11
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/CSFML/Network/Ftp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include <CSFML/Network/FtpStruct.hpp>

#include <SFML/Network/IpAddress.hpp>
#include <SFML/System/String.hpp>

#include <cstring>

Expand All @@ -47,14 +46,14 @@ static_assert(alignof(sfChar32) == alignof(char32_t));
////////////////////////////////////////////////////////////
// Define utils to copy to sfChar32
////////////////////////////////////////////////////////////
[[nodiscard]] sfChar32* copyToChar32(const sf::String& str)
[[nodiscard]] sfChar32* copyToChar32(const std::string& str)
{
const std::size_t byteCount = sizeof(sfChar32) * str.getSize();
const std::size_t byteCount = sizeof(sfChar32) * str.size();
auto* utf32 = static_cast<sfChar32*>(std::malloc(byteCount + sizeof(sfChar32)));
if (!utf32)
return nullptr;
std::memcpy(utf32, str.getData(), byteCount);
utf32[str.getSize()] = 0;
std::memcpy(utf32, str.data(), byteCount);
utf32[str.size()] = 0;

return utf32;
}
Expand Down Expand Up @@ -151,7 +150,7 @@ const char* sfFtpDirectoryResponse_getDirectory(const sfFtpDirectoryResponse* ft
const sfChar32* sfFtpDirectoryResponse_getDirectoryUnicode(const sfFtpDirectoryResponse* ftpDirectoryResponse)
{
assert(ftpDirectoryResponse);
return copyToChar32(sf::String(ftpDirectoryResponse->getDirectory().string()));
return copyToChar32(ftpDirectoryResponse->getDirectory().string());
}


Expand Down

0 comments on commit 0bdbb11

Please sign in to comment.