lib/mu: use fmt-based time/date formatting

For a small speedup
This commit is contained in:
Dirk-Jan C. Binnema 2023-08-05 10:53:11 +03:00
parent 27c07280b1
commit 4945e699c8
8 changed files with 22 additions and 24 deletions

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2020-2022 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** Copyright (C) 2020-2023 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
**
** This program is free software; you can redistribute it and/or modify it
** under the terms of the GNU General Public License as published by the
@ -115,7 +115,7 @@ struct Indexer::Private {
Scanner scanner_;
const size_t max_message_size_;
time_t dirstamp_{};
::time_t dirstamp_{};
std::size_t max_workers_;
std::vector<std::thread> workers_;
std::thread scanner_worker_;
@ -161,9 +161,8 @@ Indexer::Private::handler(const std::string& fullpath, struct stat* statbuf,
dirstamp_ = store_.dirstamp(fullpath);
if (conf_.lazy_check && dirstamp_ >= statbuf->st_ctime &&
htype == Scanner::HandleType::EnterNewCur) {
mu_debug("skip {} (seems up-to-date: {} >= {})", fullpath,
time_to_string("%FT%T", dirstamp_),
time_to_string("%FT%T", statbuf->st_ctime));
mu_debug("skip {} (seems up-to-date: {:%FT%T} >= {:%FT%T})",
fullpath, mu_time(dirstamp_), mu_time(statbuf->st_ctime));
return false;
}
@ -461,7 +460,7 @@ Indexer::progress() const
return priv_->progress_;
}
time_t
::time_t
Indexer::completed() const
{
return priv_->completed_;

View File

@ -115,7 +115,7 @@ public:
*
* @return the time or 0
*/
time_t completed() const;
::time_t completed() const;
private:
struct Private;

View File

@ -532,12 +532,11 @@ Server::Private::contacts_handler(const Command& cmd)
const auto tstampstr = cmd.string_arg(":tstamp").value_or("");
const auto maxnum = cmd.number_arg(":maxnum").value_or(0 /*unlimited*/);
const auto after{afterstr.empty() ? 0 :
parse_date_time(afterstr, true).value_or(0)};
const auto after{afterstr.empty() ? 0 : parse_date_time(afterstr, true).value_or(0)};
const auto tstamp = g_ascii_strtoll(tstampstr.c_str(), NULL, 10);
mu_debug("find {} contacts last seen >= {} (tstamp: {})",
personal ? "personal" : "any", time_to_string("%c", after), tstamp);
mu_debug("find {} contacts last seen >= {:%c} (tstamp: {})",
personal ? "personal" : "any", mu_time(after), tstamp);
auto match_contact = [&](const Contact& ci)->bool {
if (tstamp > ci.tstamp)

View File

@ -171,12 +171,12 @@ output_bbdb(ItemType itype, OptContact contact, const Options& opts)
return;
const auto names{guess_first_last_name(contact->name)};
const auto now{time_to_string("%Y-%m-%d", ::time(NULL))};
const auto timestamp{time_to_string("%Y-%m-%d", contact->message_date)};
const auto now{mu_format("{:%Y-%m-%d}", mu_time(::time({})))};
const auto timestamp{mu_format("{:%Y-%m-%d}", mu_time(contact->message_date))};
mu_println("[\"{}\" \"{}\" nil nil nil nil (\"{}\") "
"((creation-date . \"{}\") (time-stamp . \"{}\")) nil]",
names.first, names.second, contact->email, now, timestamp);
"((creation-date . \"{}\") (time-stamp . \"{}\")) nil]",
names.first, names.second, contact->email, now, timestamp);
}
static void
@ -212,7 +212,7 @@ output_json(ItemType itype, OptContact contact, const Options& opts)
name,
Mu::quote(contact->display_name()),
contact->message_date,
time_to_string("%FT%TZ", contact->message_date, true/*utc*/),
mu_format("{:%FT%TZ}", mu_time(contact->message_date, true/*utc*/)),
contact->personal ? "true" : "false",
contact->frequency);
mu_print(" }}");

View File

@ -234,8 +234,8 @@ display_field(const Message& msg, Field::Id field_id)
} else /* as string */
return msg.document().string_value(field_id);
case Field::Type::TimeT:
return time_to_string(
"%c", static_cast<::time_t>(msg.document().integer_value(field_id)));
return mu_format("{:%c}",
mu_time(msg.document().integer_value(field_id)));
case Field::Type::ByteSize:
return to_string(msg.document().integer_value(field_id));
case Field::Type::StringList:

View File

@ -182,7 +182,7 @@ topic_store(const Mu::Store& store, const Options& opts)
if (t == 0)
return "never";
else
return time_to_string("%c", t);
return mu_format("{:%c}", mu_time(t));
};
Table info;

View File

@ -46,12 +46,12 @@ print_signature(const Mu::MimeSignature& sig, const Options& opts)
const auto created{sig.created()};
key_val(col, "created",
created == 0 ? "unknown" :
time_to_string("%c", sig.created()).c_str());
created == 0 ? std::string{"unknown"} :
mu_format("{:%c}", mu_time(sig.created())));
const auto expires{sig.expires()};
key_val(col, "expires", expires==0 ? "never" :
time_to_string("%c", sig.expires()).c_str());
key_val(col, "expires", expires==0 ? std::string{"never"} :
mu_format("{:%c}", mu_time(sig.expires())));
const auto cert{sig.certificate()};
key_val(col, "public-key algo",

View File

@ -140,7 +140,7 @@ view_msg_plain(const Message& message, const Options& opts)
print_field("Subject", message.subject(), color);
if (auto&& date = message.date(); date != 0)
print_field("Date", time_to_string("%c", date), color);
print_field("Date", mu_format("{:%c}", mu_time(date)), color);
print_field("Tags", join(message.tags(), ", "), color);