refactor: remove evbuffer_free_to_str() (#2967)

This commit is contained in:
Charles Kerr 2022-04-22 13:05:49 -05:00 committed by GitHub
parent 32facb50d7
commit ed897f93f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 19 deletions

View File

@ -734,15 +734,15 @@ static void tr_logAddTrace_tier_announce_queue(tr_tier const* tier)
return;
}
auto* const buf = evbuffer_new();
for (size_t i = 0, n = std::size(tier->announce_events); i < n; ++i)
auto buf = std::string{};
auto const& events = tier->announce_events;
buf.reserve(std::size(events) * 20);
for (size_t i = 0, n = std::size(events); i < n; ++i)
{
tr_announce_event const e = tier->announce_events[i];
char const* str = tr_announce_event_get_string(e);
evbuffer_add_printf(buf, "[%zu:%s]", i, str);
fmt::format_to(std::back_inserter(buf), FMT_STRING("[{:d}:{:s}]"), i, tr_announce_event_get_string(events[i]));
}
tr_logAddTraceTier(tier, evbuffer_free_to_str(buf));
tr_logAddTraceTier(tier, buf);
}
// higher priorities go to the front of the announce queue

View File

@ -367,16 +367,6 @@ tr_disk_space tr_dirSpace(std::string_view dir)
*****
****/
std::string evbuffer_free_to_str(evbuffer* buf)
{
auto const n = evbuffer_get_length(buf);
auto ret = std::string{};
ret.resize(n);
evbuffer_copyout(buf, std::data(ret), n);
evbuffer_free(buf);
return ret;
}
char* tr_strvDup(std::string_view in)
{
auto const n = std::size(in);

View File

@ -239,8 +239,6 @@ constexpr bool tr_str_is_empty(char const* value)
return value == nullptr || *value == '\0';
}
std::string evbuffer_free_to_str(evbuffer* buf);
/** @brief Portability wrapper for strlcpy() that uses the system implementation if available */
size_t tr_strlcpy(void* dst, void const* src, size_t siz);

View File

@ -1203,7 +1203,13 @@ struct evbuffer* tr_variantToBuf(tr_variant const* v, tr_variant_fmt fmt)
std::string tr_variantToStr(tr_variant const* v, tr_variant_fmt fmt)
{
return evbuffer_free_to_str(tr_variantToBuf(v, fmt));
auto* const buf = tr_variantToBuf(v, fmt);
auto const n = evbuffer_get_length(buf);
auto str = std::string{};
str.resize(n);
evbuffer_copyout(buf, std::data(str), n);
evbuffer_free(buf);
return str;
}
int tr_variantToFile(tr_variant const* v, tr_variant_fmt fmt, std::string_view filename)