Partial rollback of CompactString after benchmarking (or 'premature optimization is the root of all evil')
This commit is contained in:
@@ -12,6 +12,7 @@ pub mod utils;
|
||||
use std::{collections::BTreeMap, time::Duration};
|
||||
|
||||
use ahash::AHashMap;
|
||||
use compact_str::CompactString;
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Debug, Default, Serialize)]
|
||||
@@ -190,7 +191,11 @@ impl Config {
|
||||
),
|
||||
};
|
||||
|
||||
trc::error!(trc::EventType::Config(cause).into_err().details(message));
|
||||
trc::error!(
|
||||
trc::EventType::Config(cause)
|
||||
.into_err()
|
||||
.details(CompactString::from(message))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,7 +227,11 @@ impl Config {
|
||||
),
|
||||
};
|
||||
|
||||
trc::error!(trc::EventType::Config(cause).into_err().details(message));
|
||||
trc::error!(
|
||||
trc::EventType::Config(cause)
|
||||
.into_err()
|
||||
.details(CompactString::from(message))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ use std::{
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use compact_str::CompactString;
|
||||
use mail_auth::{
|
||||
IpLookupStrategy,
|
||||
common::crypto::{Algorithm, HashAlgorithm},
|
||||
@@ -639,26 +638,6 @@ impl AsKey for &str {
|
||||
}
|
||||
}
|
||||
|
||||
impl AsKey for CompactString {
|
||||
fn as_key(&self) -> String {
|
||||
self.to_string()
|
||||
}
|
||||
|
||||
fn as_prefix(&self) -> String {
|
||||
format!("{self}.")
|
||||
}
|
||||
}
|
||||
|
||||
impl AsKey for &CompactString {
|
||||
fn as_key(&self) -> String {
|
||||
self.to_string()
|
||||
}
|
||||
|
||||
fn as_prefix(&self) -> String {
|
||||
format!("{self}.")
|
||||
}
|
||||
}
|
||||
|
||||
impl AsKey for String {
|
||||
fn as_key(&self) -> String {
|
||||
self.to_string()
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
|
||||
use std::{fmt::Display, iter::Peekable, slice::Iter};
|
||||
|
||||
use compact_str::format_compact;
|
||||
|
||||
use super::{Ignore, JsonObjectParser, Token};
|
||||
|
||||
const MAX_NESTED_LEVELS: u32 = 16;
|
||||
@@ -39,18 +41,18 @@ impl<'x> Parser<'x> {
|
||||
pub fn error(&self, message: &str) -> trc::Error {
|
||||
trc::JmapEvent::NotJson
|
||||
.into_err()
|
||||
.details(format!("{message} at position {}.", self.pos))
|
||||
.details(format_compact!("{message} at position {}.", self.pos))
|
||||
}
|
||||
|
||||
pub fn error_unterminated(&self) -> trc::Error {
|
||||
trc::JmapEvent::NotJson.into_err().details(format!(
|
||||
trc::JmapEvent::NotJson.into_err().details(format_compact!(
|
||||
"Unterminated string at position {pos}.",
|
||||
pos = self.pos
|
||||
))
|
||||
}
|
||||
|
||||
pub fn error_utf8(&self) -> trc::Error {
|
||||
trc::JmapEvent::NotJson.into_err().details(format!(
|
||||
trc::JmapEvent::NotJson.into_err().details(format_compact!(
|
||||
"Invalid UTF-8 sequence at position {pos}.",
|
||||
pos = self.pos
|
||||
))
|
||||
@@ -58,11 +60,13 @@ impl<'x> Parser<'x> {
|
||||
|
||||
pub fn error_value(&mut self) -> trc::Error {
|
||||
if self.is_eof || self.skip_string() {
|
||||
trc::JmapEvent::InvalidArguments.into_err().details(format!(
|
||||
"Invalid value {:?} at position {}.",
|
||||
String::from_utf8_lossy(self.bytes[self.pos_marker..self.pos - 1].as_ref()),
|
||||
self.pos
|
||||
))
|
||||
trc::JmapEvent::InvalidArguments
|
||||
.into_err()
|
||||
.details(format_compact!(
|
||||
"Invalid value {:?} at position {}.",
|
||||
String::from_utf8_lossy(self.bytes[self.pos_marker..self.pos - 1].as_ref()),
|
||||
self.pos
|
||||
))
|
||||
} else {
|
||||
self.error_unterminated()
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
|
||||
use std::fmt::Display;
|
||||
|
||||
use compact_str::format_compact;
|
||||
|
||||
use self::json::Parser;
|
||||
|
||||
pub mod base32;
|
||||
@@ -118,18 +120,24 @@ impl<T: Eq> Token<T> {
|
||||
if self == token {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(trc::JmapEvent::NotRequest.into_err().details(format!(
|
||||
"Invalid JMAP request: expected '{token}', got '{self}'."
|
||||
)))
|
||||
Err(trc::JmapEvent::NotRequest
|
||||
.into_err()
|
||||
.details(format_compact!(
|
||||
"Invalid JMAP request: expected '{token}', got '{self}'."
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn error(&self, property: &str, expected: &str) -> trc::Error {
|
||||
trc::JmapEvent::InvalidArguments.into_err().details(if !property.is_empty() {
|
||||
format!("Invalid argument for '{property:?}': expected '{expected}', got '{self}'.",)
|
||||
} else {
|
||||
format!("Invalid argument: expected '{expected}', got '{self}'.")
|
||||
})
|
||||
trc::JmapEvent::InvalidArguments
|
||||
.into_err()
|
||||
.details(if !property.is_empty() {
|
||||
format_compact!(
|
||||
"Invalid argument for '{property:?}': expected '{expected}', got '{self}'.",
|
||||
)
|
||||
} else {
|
||||
format_compact!("Invalid argument: expected '{expected}', got '{self}'.")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ pub mod snowflake;
|
||||
pub mod topological;
|
||||
pub mod url_params;
|
||||
|
||||
use compact_str::CompactString;
|
||||
use compact_str::ToCompactString;
|
||||
use futures::StreamExt;
|
||||
use reqwest::Response;
|
||||
use rustls::{
|
||||
@@ -215,7 +215,7 @@ impl<T> UnwrapFailure<T> for Option<T> {
|
||||
None => {
|
||||
trc::event!(
|
||||
Server(trc::ServerEvent::StartupError),
|
||||
Details = message.to_string()
|
||||
Details = message.to_compact_string()
|
||||
);
|
||||
eprintln!("{message}");
|
||||
std::process::exit(1);
|
||||
@@ -231,8 +231,8 @@ impl<T, E: std::fmt::Display> UnwrapFailure<T> for Result<T, E> {
|
||||
Err(err) => {
|
||||
trc::event!(
|
||||
Server(trc::ServerEvent::StartupError),
|
||||
Details = message.to_string(),
|
||||
Reason = err.to_string()
|
||||
Details = message.to_compact_string(),
|
||||
Reason = err.to_compact_string()
|
||||
);
|
||||
|
||||
#[cfg(feature = "test_mode")]
|
||||
@@ -251,7 +251,7 @@ impl<T, E: std::fmt::Display> UnwrapFailure<T> for Result<T, E> {
|
||||
pub fn failed(message: &str) -> ! {
|
||||
trc::event!(
|
||||
Server(trc::ServerEvent::StartupError),
|
||||
Details = message.to_string(),
|
||||
Details = message.to_compact_string(),
|
||||
);
|
||||
eprintln!("{message}");
|
||||
std::process::exit(1);
|
||||
@@ -365,8 +365,8 @@ impl ServerCertVerifier for DummyVerifier {
|
||||
}
|
||||
|
||||
// Basic email sanitizer
|
||||
pub fn sanitize_email(email: &str) -> Option<CompactString> {
|
||||
let mut result = CompactString::with_capacity(email.len());
|
||||
pub fn sanitize_email(email: &str) -> Option<String> {
|
||||
let mut result = String::with_capacity(email.len());
|
||||
let mut found_local = false;
|
||||
let mut found_domain = false;
|
||||
let mut last_ch = char::from(0);
|
||||
|
||||
Reference in New Issue
Block a user