mu-contact: move ctor parameters

Small optimization; and remove some dead-code; use is_ascii_cntrl.
This commit is contained in:
Dirk-Jan C. Binnema
2026-07-23 11:13:09 +03:00
committed by Seth Ladygo
parent 19b2bdd6e4
commit 2750fe9f27
2 changed files with 7 additions and 25 deletions

View File

@ -24,12 +24,12 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <functional> #include <functional>
#include <cctype>
#include <cstring> #include <cstring>
#include <cstdlib> #include <cstdlib>
#include <ctime> #include <ctime>
#include <utils/mu-option.hh> #include <utils/mu-option.hh>
#include <utils/mu-utils.hh>
#include "mu-fields.hh" #include "mu-fields.hh"
namespace Mu { namespace Mu {
@ -47,9 +47,9 @@ struct Contact {
* @param type contact field type * @param type contact field type
* @param message_date data for the message for this contact * @param message_date data for the message for this contact
*/ */
Contact(const std::string& email, const std::string& name = {}, Contact(std::string email, std::string name = {},
Type type = {}, int64_t message_date ={}) Type type = {}, int64_t message_date ={})
: email{email}, name{name}, type{type}, : email{std::move(email)}, name{std::move(name)}, type{type},
message_date{message_date}, personal{}, frequency{1}, tstamp{} message_date{message_date}, personal{}, frequency{1}, tstamp{}
{ cleanup_name(); } { cleanup_name(); }
@ -63,10 +63,10 @@ struct Contact {
* @param freq how often was this contact seen? * @param freq how often was this contact seen?
* @param tstamp timestamp for last change * @param tstamp timestamp for last change
*/ */
Contact(const std::string& email, const std::string& name, Contact(std::string email, std::string name,
int64_t message_date, bool personal, size_t freq, int64_t message_date, bool personal, size_t freq,
int64_t tstamp) int64_t tstamp)
: email{email}, name{name}, type{}, : email{std::move(email)}, name{std::move(name)}, type{},
message_date{message_date}, personal{personal}, frequency{freq}, message_date{message_date}, personal{personal}, frequency{freq},
tstamp{tstamp} tstamp{tstamp}
{ cleanup_name(); } { cleanup_name(); }
@ -83,14 +83,6 @@ struct Contact {
*/ */
std::string display_name() const; std::string display_name() const;
/**
* Does the contact contain a valid email address as per
* https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address
* ?
* @return true or false
*/
bool has_valid_email() const;
/** /**
* Operator==; based on the e-mail address only * Operator==; based on the e-mail address only
* *
@ -101,16 +93,6 @@ struct Contact {
bool operator== (const Contact& rhs) const noexcept { bool operator== (const Contact& rhs) const noexcept {
return email == rhs.email; return email == rhs.email;
} }
/**
* Operator!=
*
* @param rhs some other Contact
*
* @return true or false.
*/
bool operator!= (const Contact& rhs) const noexcept {
return !(*this == rhs);
}
static constexpr int64_t RecentOffset{15 * 24 * 3600}; static constexpr int64_t RecentOffset{15 * 24 * 3600};
/**< Contacts seen after now - RecentOffset seconds are considered /**< Contacts seen after now - RecentOffset seconds are considered
@ -184,7 +166,7 @@ struct Contact {
private: private:
void cleanup_name() { // replace control characters by spaces. void cleanup_name() { // replace control characters by spaces.
for (auto& c: name) for (auto& c: name)
if (iscntrl(c)) if (is_ascii_cntrl(c))
c = ' '; c = ' ';
} }

View File

@ -119,7 +119,7 @@ ContactsCache::Private::deserialize(const std::string& serialized) const
std::string line; std::string line;
while (std::getline(ss, line)) { while (std::getline(ss, line)) {
const auto parts = Mu::split(line, SepaChar2); auto parts = Mu::split(line, SepaChar2);
if (G_UNLIKELY(parts.size() != 5)) { if (G_UNLIKELY(parts.size() != 5)) {
mu_warning("error: '{}'", line); mu_warning("error: '{}'", line);
continue; continue;