mirror of https://github.com/djcb/mu.git
lib/mu: use fmt-based time/date formatting
For a small speedup
This commit is contained in:
parent
27c07280b1
commit
4945e699c8
|
@ -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
|
** 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
|
** under the terms of the GNU General Public License as published by the
|
||||||
|
@ -115,7 +115,7 @@ struct Indexer::Private {
|
||||||
Scanner scanner_;
|
Scanner scanner_;
|
||||||
const size_t max_message_size_;
|
const size_t max_message_size_;
|
||||||
|
|
||||||
time_t dirstamp_{};
|
::time_t dirstamp_{};
|
||||||
std::size_t max_workers_;
|
std::size_t max_workers_;
|
||||||
std::vector<std::thread> workers_;
|
std::vector<std::thread> workers_;
|
||||||
std::thread scanner_worker_;
|
std::thread scanner_worker_;
|
||||||
|
@ -161,9 +161,8 @@ Indexer::Private::handler(const std::string& fullpath, struct stat* statbuf,
|
||||||
dirstamp_ = store_.dirstamp(fullpath);
|
dirstamp_ = store_.dirstamp(fullpath);
|
||||||
if (conf_.lazy_check && dirstamp_ >= statbuf->st_ctime &&
|
if (conf_.lazy_check && dirstamp_ >= statbuf->st_ctime &&
|
||||||
htype == Scanner::HandleType::EnterNewCur) {
|
htype == Scanner::HandleType::EnterNewCur) {
|
||||||
mu_debug("skip {} (seems up-to-date: {} >= {})", fullpath,
|
mu_debug("skip {} (seems up-to-date: {:%FT%T} >= {:%FT%T})",
|
||||||
time_to_string("%FT%T", dirstamp_),
|
fullpath, mu_time(dirstamp_), mu_time(statbuf->st_ctime));
|
||||||
time_to_string("%FT%T", statbuf->st_ctime));
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -461,7 +460,7 @@ Indexer::progress() const
|
||||||
return priv_->progress_;
|
return priv_->progress_;
|
||||||
}
|
}
|
||||||
|
|
||||||
time_t
|
::time_t
|
||||||
Indexer::completed() const
|
Indexer::completed() const
|
||||||
{
|
{
|
||||||
return priv_->completed_;
|
return priv_->completed_;
|
||||||
|
|
|
@ -115,7 +115,7 @@ public:
|
||||||
*
|
*
|
||||||
* @return the time or 0
|
* @return the time or 0
|
||||||
*/
|
*/
|
||||||
time_t completed() const;
|
::time_t completed() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct Private;
|
struct Private;
|
||||||
|
|
|
@ -532,12 +532,11 @@ Server::Private::contacts_handler(const Command& cmd)
|
||||||
const auto tstampstr = cmd.string_arg(":tstamp").value_or("");
|
const auto tstampstr = cmd.string_arg(":tstamp").value_or("");
|
||||||
const auto maxnum = cmd.number_arg(":maxnum").value_or(0 /*unlimited*/);
|
const auto maxnum = cmd.number_arg(":maxnum").value_or(0 /*unlimited*/);
|
||||||
|
|
||||||
const auto after{afterstr.empty() ? 0 :
|
const auto after{afterstr.empty() ? 0 : parse_date_time(afterstr, true).value_or(0)};
|
||||||
parse_date_time(afterstr, true).value_or(0)};
|
|
||||||
const auto tstamp = g_ascii_strtoll(tstampstr.c_str(), NULL, 10);
|
const auto tstamp = g_ascii_strtoll(tstampstr.c_str(), NULL, 10);
|
||||||
|
|
||||||
mu_debug("find {} contacts last seen >= {} (tstamp: {})",
|
mu_debug("find {} contacts last seen >= {:%c} (tstamp: {})",
|
||||||
personal ? "personal" : "any", time_to_string("%c", after), tstamp);
|
personal ? "personal" : "any", mu_time(after), tstamp);
|
||||||
|
|
||||||
auto match_contact = [&](const Contact& ci)->bool {
|
auto match_contact = [&](const Contact& ci)->bool {
|
||||||
if (tstamp > ci.tstamp)
|
if (tstamp > ci.tstamp)
|
||||||
|
|
|
@ -171,8 +171,8 @@ output_bbdb(ItemType itype, OptContact contact, const Options& opts)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const auto names{guess_first_last_name(contact->name)};
|
const auto names{guess_first_last_name(contact->name)};
|
||||||
const auto now{time_to_string("%Y-%m-%d", ::time(NULL))};
|
const auto now{mu_format("{:%Y-%m-%d}", mu_time(::time({})))};
|
||||||
const auto timestamp{time_to_string("%Y-%m-%d", contact->message_date)};
|
const auto timestamp{mu_format("{:%Y-%m-%d}", mu_time(contact->message_date))};
|
||||||
|
|
||||||
mu_println("[\"{}\" \"{}\" nil nil nil nil (\"{}\") "
|
mu_println("[\"{}\" \"{}\" nil nil nil nil (\"{}\") "
|
||||||
"((creation-date . \"{}\") (time-stamp . \"{}\")) nil]",
|
"((creation-date . \"{}\") (time-stamp . \"{}\")) nil]",
|
||||||
|
@ -212,7 +212,7 @@ output_json(ItemType itype, OptContact contact, const Options& opts)
|
||||||
name,
|
name,
|
||||||
Mu::quote(contact->display_name()),
|
Mu::quote(contact->display_name()),
|
||||||
contact->message_date,
|
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->personal ? "true" : "false",
|
||||||
contact->frequency);
|
contact->frequency);
|
||||||
mu_print(" }}");
|
mu_print(" }}");
|
||||||
|
|
|
@ -234,8 +234,8 @@ display_field(const Message& msg, Field::Id field_id)
|
||||||
} else /* as string */
|
} else /* as string */
|
||||||
return msg.document().string_value(field_id);
|
return msg.document().string_value(field_id);
|
||||||
case Field::Type::TimeT:
|
case Field::Type::TimeT:
|
||||||
return time_to_string(
|
return mu_format("{:%c}",
|
||||||
"%c", static_cast<::time_t>(msg.document().integer_value(field_id)));
|
mu_time(msg.document().integer_value(field_id)));
|
||||||
case Field::Type::ByteSize:
|
case Field::Type::ByteSize:
|
||||||
return to_string(msg.document().integer_value(field_id));
|
return to_string(msg.document().integer_value(field_id));
|
||||||
case Field::Type::StringList:
|
case Field::Type::StringList:
|
||||||
|
|
|
@ -182,7 +182,7 @@ topic_store(const Mu::Store& store, const Options& opts)
|
||||||
if (t == 0)
|
if (t == 0)
|
||||||
return "never";
|
return "never";
|
||||||
else
|
else
|
||||||
return time_to_string("%c", t);
|
return mu_format("{:%c}", mu_time(t));
|
||||||
};
|
};
|
||||||
|
|
||||||
Table info;
|
Table info;
|
||||||
|
|
|
@ -46,12 +46,12 @@ print_signature(const Mu::MimeSignature& sig, const Options& opts)
|
||||||
|
|
||||||
const auto created{sig.created()};
|
const auto created{sig.created()};
|
||||||
key_val(col, "created",
|
key_val(col, "created",
|
||||||
created == 0 ? "unknown" :
|
created == 0 ? std::string{"unknown"} :
|
||||||
time_to_string("%c", sig.created()).c_str());
|
mu_format("{:%c}", mu_time(sig.created())));
|
||||||
|
|
||||||
const auto expires{sig.expires()};
|
const auto expires{sig.expires()};
|
||||||
key_val(col, "expires", expires==0 ? "never" :
|
key_val(col, "expires", expires==0 ? std::string{"never"} :
|
||||||
time_to_string("%c", sig.expires()).c_str());
|
mu_format("{:%c}", mu_time(sig.expires())));
|
||||||
|
|
||||||
const auto cert{sig.certificate()};
|
const auto cert{sig.certificate()};
|
||||||
key_val(col, "public-key algo",
|
key_val(col, "public-key algo",
|
||||||
|
|
|
@ -140,7 +140,7 @@ view_msg_plain(const Message& message, const Options& opts)
|
||||||
print_field("Subject", message.subject(), color);
|
print_field("Subject", message.subject(), color);
|
||||||
|
|
||||||
if (auto&& date = message.date(); date != 0)
|
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);
|
print_field("Tags", join(message.tags(), ", "), color);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue