Fix some string to Slice conversions.

GitOrigin-RevId: 79ddee1a90c633cc1b1df5c8e3d9917027bad0f3
This commit is contained in:
levlam 2018-07-08 02:47:46 +03:00
parent 1ab40c7278
commit e2a90b9edf
22 changed files with 44 additions and 46 deletions

View File

@ -200,7 +200,7 @@ class SeqKvBench : public td::Benchmark {
td::SeqKeyValue kv;
void run(int n) override {
for (int i = 0; i < n; i++) {
kv.set(td::to_string(i % 10), td::to_string(i));
kv.set(PSLICE() << i % 10, PSLICE() << i);
}
}
};

View File

@ -219,7 +219,7 @@ class CreateFileBench : public Benchmark {
}
void run(int n) override {
for (int i = 0; i < n; i++) {
FileFd::open("A/" + to_string(i), FileFd::Flags::Write | FileFd::Flags::Create).move_as_ok().close();
FileFd::open(PSLICE() << "A/" << i, FileFd::Flags::Write | FileFd::Flags::Create).move_as_ok().close();
}
}
void tear_down() override {
@ -232,6 +232,7 @@ class CreateFileBench : public Benchmark {
});
}
};
class WalkPathBench : public Benchmark {
string get_description() const override {
return "walk_path";
@ -239,7 +240,7 @@ class WalkPathBench : public Benchmark {
void start_up_n(int n) override {
mkdir("A").ensure();
for (int i = 0; i < n; i++) {
FileFd::open("A/" + to_string(i), FileFd::Flags::Write | FileFd::Flags::Create).move_as_ok().close();
FileFd::open(PSLICE() << "A/" << i, FileFd::Flags::Write | FileFd::Flags::Create).move_as_ok().close();
}
}
void run(int n) override {

View File

@ -109,7 +109,7 @@ Status AuthKeyHandshake::on_res_pq(Slice message, Callback *connection, PublicRs
// req_DH_params#d712e4be nonce:int128 server_nonce:int128 p:string q:string public_key_fingerprint:long
// encrypted_data:string = Server_DH_Params
mtproto_api::req_DH_params req_dh_params(nonce, server_nonce, p, q, rsa_fingerprint, std::move(encrypted_data));
mtproto_api::req_DH_params req_dh_params(nonce, server_nonce, p, q, rsa_fingerprint, encrypted_data);
send(connection, create_storer(req_dh_params));
state_ = ServerDHParams;
@ -202,7 +202,7 @@ Status AuthKeyHandshake::on_server_dh_params(Slice message, Callback *connection
tmp_KDF(server_nonce, new_nonce, &tmp_aes_key, &tmp_aes_iv);
aes_ige_encrypt(tmp_aes_key, &tmp_aes_iv, encrypted_data, encrypted_data);
mtproto_api::set_client_DH_params set_client_dh_params(nonce, server_nonce, std::move(encrypted_data_str));
mtproto_api::set_client_DH_params set_client_dh_params(nonce, server_nonce, encrypted_data);
send(connection, create_storer(set_client_dh_params));
auth_key = AuthKey(dh_auth_key_id(auth_key_str), std::move(auth_key_str));

View File

@ -5185,7 +5185,7 @@ void ContactsManager::on_binlog_user_event(BinlogEvent &&event) {
}
string ContactsManager::get_user_database_key(UserId user_id) {
return "us" + to_string(user_id.get());
return PSTRING() << "us" << user_id.get();
}
string ContactsManager::get_user_database_value(const User *u) {
@ -5434,7 +5434,7 @@ void ContactsManager::on_binlog_chat_event(BinlogEvent &&event) {
}
string ContactsManager::get_chat_database_key(ChatId chat_id) {
return "gr" + to_string(chat_id.get());
return PSTRING() << "gr" << chat_id.get();
}
string ContactsManager::get_chat_database_value(const Chat *c) {
@ -5657,7 +5657,7 @@ void ContactsManager::on_binlog_channel_event(BinlogEvent &&event) {
}
string ContactsManager::get_channel_database_key(ChannelId channel_id) {
return "ch" + to_string(channel_id.get());
return PSTRING() << "ch" << channel_id.get();
}
string ContactsManager::get_channel_database_value(const Channel *c) {
@ -5874,7 +5874,7 @@ void ContactsManager::on_binlog_secret_chat_event(BinlogEvent &&event) {
}
string ContactsManager::get_secret_chat_database_key(SecretChatId secret_chat_id) {
return "sc" + to_string(secret_chat_id.get());
return PSTRING() << "sc" << secret_chat_id.get();
}
string ContactsManager::get_secret_chat_database_value(const SecretChat *c) {

View File

@ -645,7 +645,7 @@ void InlineQueriesManager::answer_inline_query(int64 inline_query_id, bool is_pe
type = "geo";
id = std::move(location->id_);
title = std::move(location->title_);
description = to_string(location->location_->latitude_) + " " + to_string(location->location_->longitude_);
description = PSTRING() << location->location_->latitude_ << ' ' << location->location_->longitude_;
thumbnail_url = std::move(location->thumbnail_url_);
// duration = location->live_period_;
if (!thumbnail_url.empty()) {

View File

@ -25246,8 +25246,8 @@ void MessagesManager::update_last_dialog_date() {
}
if (G()->parameters().use_message_db && last_database_server_dialog_date_ < last_server_dialog_date_) {
auto last_server_dialog_date_string = to_string(last_server_dialog_date_.get_order()) + " " +
to_string(last_server_dialog_date_.get_dialog_id().get());
auto last_server_dialog_date_string = PSTRING() << last_server_dialog_date_.get_order() << ' '
<< last_server_dialog_date_.get_dialog_id().get();
G()->td_db()->get_binlog_pmc()->set("last_server_dialog_date", last_server_dialog_date_string);
LOG(INFO) << "Save last server dialog date " << last_server_dialog_date_string;
last_database_server_dialog_date_ = last_server_dialog_date_;
@ -25385,7 +25385,7 @@ void MessagesManager::load_notification_settings() {
string MessagesManager::get_channel_pts_key(DialogId dialog_id) {
CHECK(dialog_id.get_type() == DialogType::Channel);
auto channel_id = dialog_id.get_channel_id();
return "ch.p" + to_string(channel_id.get());
return PSTRING() << "ch.p" << channel_id.get();
}
int32 MessagesManager::load_channel_pts(DialogId dialog_id) const {

View File

@ -316,7 +316,7 @@ EncryptedSecureFile get_encrypted_secure_file(FileManager *file_manager,
}
result.file.file_id = file_manager->register_remote(
FullRemoteFileLocation(FileType::Secure, secure_file->id_, secure_file->access_hash_, DcId::internal(dc_id)),
FileLocationSource::FromServer, DialogId(), 0, secure_file->size_, to_string(secure_file->id_) + ".jpg");
FileLocationSource::FromServer, DialogId(), 0, secure_file->size_, PSTRING() << secure_file->id_ << ".jpg");
result.file.date = secure_file->date_;
if (result.file.date < 0) {
LOG(ERROR) << "Receive wrong date " << result.file.date;

View File

@ -1025,7 +1025,7 @@ std::pair<int64, FileId> StickersManager::on_get_sticker_document(tl_object_ptr<
int64 document_id = document->id_;
FileId sticker_id = td_->file_manager_->register_remote(
FullRemoteFileLocation(FileType::Sticker, document_id, document->access_hash_, DcId::internal(document->dc_id_)),
FileLocationSource::FromServer, DialogId(), document->size_, 0, to_string(document_id) + ".webp");
FileLocationSource::FromServer, DialogId(), document->size_, 0, PSTRING() << document_id << ".webp");
PhotoSize thumbnail = get_photo_size(td_->file_manager_.get(), FileType::Thumbnail, 0, 0, DialogId(),
std::move(document->thumb_), has_webp_thumbnail(sticker));
@ -1471,7 +1471,7 @@ int64 StickersManager::on_get_sticker_set(tl_object_ptr<telegram_api::stickerSet
s->is_changed = true;
if (installed_sticker_sets_hints_[s->is_masks].has_key(set_id)) {
installed_sticker_sets_hints_[s->is_masks].add(set_id, s->title + " " + s->short_name);
installed_sticker_sets_hints_[s->is_masks].add(set_id, PSLICE() << s->title << ' ' << s->short_name);
}
}
if (s->short_name != set->short_name_) {
@ -1482,7 +1482,7 @@ int64 StickersManager::on_get_sticker_set(tl_object_ptr<telegram_api::stickerSet
s->is_changed = true;
if (installed_sticker_sets_hints_[s->is_masks].has_key(set_id)) {
installed_sticker_sets_hints_[s->is_masks].add(set_id, s->title + " " + s->short_name);
installed_sticker_sets_hints_[s->is_masks].add(set_id, PSLICE() << s->title << ' ' << s->short_name);
}
}
@ -2267,8 +2267,8 @@ void StickersManager::on_update_sticker_set(StickerSet *sticker_set, bool is_ins
need_update_installed_sticker_sets_[sticker_set->is_masks] = true;
if (is_added) {
installed_sticker_sets_hints_[sticker_set->is_masks].add(sticker_set->id,
sticker_set->title + " " + sticker_set->short_name);
installed_sticker_sets_hints_[sticker_set->is_masks].add(
sticker_set->id, PSLICE() << sticker_set->title << ' ' << sticker_set->short_name);
sticker_set_ids.insert(sticker_set_ids.begin(), sticker_set->id);
} else {
installed_sticker_sets_hints_[sticker_set->is_masks].remove(sticker_set->id);
@ -2396,11 +2396,11 @@ void StickersManager::on_load_installed_sticker_sets_finished(bool is_masks, vec
}
string StickersManager::get_sticker_set_database_key(int64 set_id) {
return "ss" + to_string(set_id);
return PSTRING() << "ss" << set_id;
}
string StickersManager::get_full_sticker_set_database_key(int64 set_id) {
return "ssf" + to_string(set_id);
return PSTRING() << "ssf" << set_id;
}
string StickersManager::get_sticker_set_database_value(const StickerSet *s, bool with_stickers) {

View File

@ -139,8 +139,8 @@ int64 StorageManager::get_db_size() {
};
G()->td_db()->with_db_path([&](CSlice path) { add_path(path).ignore(); });
add_path(G()->parameters().database_directory + "log").ignore();
add_path(G()->parameters().database_directory + "log.old").ignore();
add_path(PSLICE() << G()->parameters().database_directory << "log").ignore();
add_path(PSLICE() << G()->parameters().database_directory << "log.old").ignore();
return size;
}

View File

@ -1773,7 +1773,7 @@ WebPageId WebPagesManager::get_web_page_instant_view(WebPageId web_page_id, bool
}
string WebPagesManager::get_web_page_instant_view_database_key(WebPageId web_page_id) {
return "wpiv" + to_string(web_page_id.get());
return PSTRING() << "wpiv" << web_page_id.get();
}
void WebPagesManager::load_web_page_instant_view(WebPageId web_page_id, bool force_full, Promise<Unit> &&promise) {
@ -2675,7 +2675,7 @@ void WebPagesManager::on_binlog_web_page_event(BinlogEvent &&event) {
}
string WebPagesManager::get_web_page_database_key(WebPageId web_page_id) {
return "wp" + to_string(web_page_id.get());
return PSTRING() << "wp" << web_page_id.get();
}
void WebPagesManager::on_save_web_page_to_database(WebPageId web_page_id, bool success) {

View File

@ -86,7 +86,7 @@ class FileDb : public FileDbInterface {
current_pmc_id_ = id;
}
pmc.erase("file" + to_string(id));
pmc.erase(PSTRING() << "file" << id);
LOG(DEBUG) << "ERASE " << format::as_hex_dump<4>(Slice(PSLICE() << "file" << to_string(id)));
if (!remote_key.empty()) {
@ -114,7 +114,7 @@ class FileDb : public FileDbInterface {
current_pmc_id_ = id;
}
pmc.set("file" + to_string(id), file_data);
pmc.set(PSTRING() << "file" << id, file_data);
if (!remote_key.empty()) {
pmc.set(remote_key, to_string(id));
@ -162,7 +162,7 @@ class FileDb : public FileDbInterface {
}
void do_store_file_data_ref(Id id, Id new_id) {
file_pmc().set("file" + to_string(id), "@@" + to_string(new_id));
file_pmc().set(PSTRING() << "file" << id, PSTRING() << "@@" << new_id);
}
};

View File

@ -1854,7 +1854,7 @@ Result<FileId> FileManager::from_persistent_id(CSlice persistent_id, FileType fi
auto r_binary = base64url_decode(persistent_id);
if (r_binary.is_error()) {
return Status::Error(10, "Wrong remote file id specified: " + r_binary.error().message().str());
return Status::Error(10, PSLICE() << "Wrong remote file id specified: " << r_binary.error().message());
}
auto binary = r_binary.move_as_ok();
if (binary.empty()) {

View File

@ -435,7 +435,7 @@ void Session::on_closed(Status status) {
VLOG(net_query) << "resend query (on_disconnected, no ack) " << query;
query->set_message_id(0);
query->cancel_slot_.clear_event();
query->set_error(Status::Error(500, "Session failed: " + status.message().str()),
query->set_error(Status::Error(500, PSLICE() << "Session failed: " << status.message()),
current_info_->connection->get_name().str());
return_query(std::move(query));
it = sent_queries_.erase(it);

View File

@ -117,7 +117,7 @@ void test_workers(int threads_n, int workers_n, int queries_n, int query_size) {
std::vector<ActorId<PowerWorker>> workers;
for (int i = 0; i < workers_n; i++) {
int thread_id = threads_n ? i % (threads_n - 1) + 2 : 0;
workers.push_back(sched.create_actor_unsafe<PowerWorker>(thread_id, "worker" + to_string(i)).release());
workers.push_back(sched.create_actor_unsafe<PowerWorker>(thread_id, PSLICE() << "worker" << i).release());
}
sched.create_actor_unsafe<Manager>(threads_n ? 1 : 0, "manager", queries_n, query_size, std::move(workers)).release();

View File

@ -179,8 +179,8 @@ Result<BinlogInfo> ConcurrentBinlog::init(string path, const Callback &callback,
void ConcurrentBinlog::init_impl(std::unique_ptr<Binlog> binlog, int32 scheduler_id) {
path_ = binlog->get_path().str();
last_id_ = binlog->peek_next_id();
binlog_actor_ =
create_actor_on_scheduler<detail::BinlogActor>("Binlog " + path_, scheduler_id, std::move(binlog), last_id_);
binlog_actor_ = create_actor_on_scheduler<detail::BinlogActor>(PSLICE() << "Binlog " << path_, scheduler_id,
std::move(binlog), last_id_);
}
void ConcurrentBinlog::close_impl(Promise<> promise) {

View File

@ -45,7 +45,7 @@ class HttpHeaderCreator {
add_header("Content-Type", type);
}
void set_content_size(size_t size) {
add_header("Content-Length", to_string(size));
add_header("Content-Length", PSLICE() << size);
}
void set_keep_alive() {
add_header("Connection", "keep-alive");

View File

@ -70,7 +70,7 @@ Result<size_t> HttpReader::read_next(HttpQuery *query) {
if (state_ != ReadHeaders) {
flow_source_.wakeup();
if (flow_sink_.is_ready() && flow_sink_.status().is_error()) {
return Status::Error(400, "Bad Request: " + flow_sink_.status().message().str());
return Status::Error(400, PSLICE() << "Bad Request: " << flow_sink_.status().message());
}
need_size = flow_source_.get_need_size();
if (need_size == 0) {
@ -603,7 +603,7 @@ Status HttpReader::parse_json_parameters(MutableSlice parameters) {
}
auto r_key = json_string_decode(parser);
if (r_key.is_error()) {
return Status::Error(400, string("Bad Request: can't parse parameter name: ") + r_key.error().message().c_str());
return Status::Error(400, PSLICE() << "Bad Request: can't parse parameter name: " << r_key.error().message());
}
parser.skip_whitespaces();
if (!parser.try_skip(':')) {
@ -625,8 +625,7 @@ Status HttpReader::parse_json_parameters(MutableSlice parameters) {
}
}();
if (r_value.is_error()) {
return Status::Error(400,
string("Bad Request: can't parse parameter value: ") + r_value.error().message().c_str());
return Status::Error(400, PSLICE() << "Bad Request: can't parse parameter value: " << r_value.error().message());
}
query_->args_.emplace_back(r_key.move_as_ok(), r_value.move_as_ok());
@ -808,7 +807,7 @@ void HttpReader::delete_temp_file(CSlice file_name) {
if (parent.size() >= prefix_length + 7 &&
parent.substr(parent.size() - prefix_length - 7, prefix_length) == TEMP_DIRECTORY_PREFIX) {
LOG(DEBUG) << "Unlink temporary directory " << parent;
rmdir(Slice(parent.data(), parent.size() - 1).str()).ignore();
rmdir(PSLICE() << Slice(parent.data(), parent.size() - 1)).ignore();
}
}

View File

@ -59,7 +59,7 @@ void FileLog::append(CSlice cslice, int log_level) {
}
if (size_ > rotate_threshold_) {
auto status = rename(path_, path_ + ".old");
auto status = rename(path_, PSLICE() << path_ << ".old");
if (status.is_error()) {
process_fatal_error(status.message());
}

View File

@ -150,7 +150,6 @@ class Status {
#endif
break;
default:
LOG(FATAL) << "Unknown status type: " << static_cast<int8>(info.error_type);
UNREACHABLE();
break;
}
@ -218,7 +217,6 @@ class Status {
return winerror_to_string(info.error_code);
#endif
default:
LOG(FATAL) << "Unknown status type: " << static_cast<int8>(info.error_type);
UNREACHABLE();
return "";
}

View File

@ -235,7 +235,7 @@ std::enable_if_t<std::is_unsigned<T>::value, T> to_integer(Slice str) {
template <class T>
Result<T> to_integer_safe(Slice str) {
auto res = to_integer<T>(str);
if (to_string(res) != str) {
if ((PSLICE() << res) != str) {
return Status::Error(PSLICE() << "Can't parse \"" << str << "\" as number");
}
return res;

View File

@ -54,7 +54,7 @@ Status mkpath(CSlice path, int32 mode) {
Status last_error = Status::OK();
for (size_t i = 1; i < path.size(); i++) {
if (path[i] == TD_DIR_SLASH) {
last_error = mkdir(path.substr(0, i).str(), mode);
last_error = mkdir(PSLICE() << path.substr(0, i), mode);
if (last_error.is_error() && first_error.is_ok()) {
first_error = last_error.clone();
}

View File

@ -616,7 +616,7 @@ class Master : public Actor {
parent_ = parent.get();
parent_token_ = parent.token();
actor_ = create_actor<SecretChatActor>(
"SecretChat " + name_, 123,
PSLICE() << "SecretChat " << name_, 123,
std::make_unique<FakeSecretChatContext>(binlog_, key_value_, close_flag_, std::move(parent)), true);
on_binlog_replay_finish();
}
@ -698,7 +698,7 @@ class Master : public Actor {
key_value_->external_init_finish(binlog_);
actor_ = create_actor<SecretChatActor>(
"SecretChat " + name_, 123,
PSLICE() << "SecretChat " << name_, 123,
std::make_unique<FakeSecretChatContext>(binlog_, key_value_, close_flag_,
ActorShared<Master>(parent_, parent_token_)),
true);