scylladb / seastar

High performance server-side application framework

Home Page:http://seastar.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

basic_sstring should have`push_back()`

tchaikov opened this issue · comments

we need to implement constexpr void push_back(char_type ch); for basic_sstring<..>.

i found this when trying to use something like

sstring s;
fmt::format_to(std::back_inserter(s), "{}", 1);

This is a bad use case, since it will have quadratic behavior.

Maybe it's a bad idea to implement push_back as it encourages bad performance.

This is a bad use case, since it will have quadratic behavior.

It shouldn't - according to https://en.cppreference.com/w/cpp/string/basic_string/push_back, the push_back() function has "Amortized constant" complexity, which means that pushing N characters has O(N) complexity, not O(N^2).

Maybe it's a bad idea to implement push_back as it encourages bad performance.

I realize it's harder to do the longer we wait, but I really think we should think about drop sstring and use std::string (i.e., issue #634). I don't say we should do it today, but it's something we should start considering (and should have considered many years ago).
C++23 added even more features to std::string which seastar::sstring doesn't implement, and eventually we'll need :-(