mirror of
https://github.com/transmission/transmission.git
synced 2025-12-24 20:35:36 +00:00
perf: do not use tr_variant when parsing .torrent files
This commit is contained in:
@@ -21,8 +21,9 @@
|
||||
#include "transmission.h"
|
||||
|
||||
#include "net.h"
|
||||
#include "web-utils.h"
|
||||
#include "tr-strbuf.h"
|
||||
#include "utils.h"
|
||||
#include "web-utils.h"
|
||||
|
||||
using namespace std::literals;
|
||||
|
||||
@@ -251,6 +252,14 @@ bool tr_isValidTrackerScheme(std::string_view scheme)
|
||||
return std::find(std::begin(Schemes), std::end(Schemes), scheme) != std::end(Schemes);
|
||||
}
|
||||
|
||||
bool isAsciiLowerCase(std::string_view host)
|
||||
{
|
||||
return std::all_of(
|
||||
std::begin(host),
|
||||
std::end(host),
|
||||
[](unsigned char ch) { return (ch < 128) && (std::islower(ch) != 0); });
|
||||
}
|
||||
|
||||
// www.example.com -> example
|
||||
// www.example.co.uk -> example
|
||||
// 127.0.0.1 -> 127.0.0.1
|
||||
@@ -262,16 +271,25 @@ std::string_view getSiteName(std::string_view host)
|
||||
return host;
|
||||
}
|
||||
|
||||
// psl needs a zero-terminated hostname
|
||||
auto const szhost = tr_urlbuf{ host };
|
||||
|
||||
// is it an IP?
|
||||
auto addr = tr_address{};
|
||||
auto const szhost = std::string(host);
|
||||
if (tr_address_from_string(&addr, szhost.c_str()))
|
||||
if (tr_address_from_string(&addr, std::data(szhost)))
|
||||
{
|
||||
return host;
|
||||
}
|
||||
|
||||
// is it a registered name?
|
||||
if (char* lower = nullptr; psl_str_to_utf8lower(szhost.c_str(), nullptr, nullptr, &lower) == PSL_SUCCESS)
|
||||
if (isAsciiLowerCase(host))
|
||||
{
|
||||
if (char const* const top = psl_registrable_domain(psl_builtin(), std::data(szhost)); top != nullptr)
|
||||
{
|
||||
host.remove_prefix(top - std::data(szhost));
|
||||
}
|
||||
}
|
||||
else if (char* lower = nullptr; psl_str_to_utf8lower(std::data(szhost), nullptr, nullptr, &lower) == PSL_SUCCESS)
|
||||
{
|
||||
// www.example.com -> example.com
|
||||
if (char const* const top = psl_registrable_domain(psl_builtin(), lower); top != nullptr)
|
||||
|
||||
Reference in New Issue
Block a user