Partial rollback of CompactString after benchmarking (or 'premature optimization is the root of all evil')

This commit is contained in:
mdecimus
2025-04-16 11:15:43 +02:00
parent d6dc6ee8c5
commit c5596fb656
189 changed files with 1318 additions and 1332 deletions

View File

@@ -701,6 +701,21 @@ impl<'x> TryFrom<Variable<'x>> for CompactString {
}
}
impl<'x> TryFrom<Variable<'x>> for String {
type Error = ();
fn try_from(value: Variable<'x>) -> Result<Self, Self::Error> {
if let Variable::String(s) = value {
Ok(match s {
StringCow::Borrowed(v) => v.to_string(),
StringCow::Owned(v) => v.into_string(),
})
} else {
Err(())
}
}
}
impl<'x> From<Variable<'x>> for bool {
fn from(val: Variable<'x>) -> Self {
val.to_bool()

View File

@@ -23,14 +23,14 @@ pub struct IfThen {
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct IfBlock {
pub key: CompactString,
pub key: String,
pub if_then: Vec<IfThen>,
pub default: Expression,
}
impl IfBlock {
pub fn new<T: ConstantValue>(
key: impl Into<CompactString>,
key: impl Into<String>,
if_thens: impl IntoIterator<Item = (&'static str, &'static str)>,
default: impl AsRef<str>,
) -> Self {
@@ -51,7 +51,7 @@ impl IfBlock {
}
}
pub fn empty(key: impl Into<CompactString>) -> Self {
pub fn empty(key: impl Into<String>) -> Self {
Self {
key: key.into(),
if_then: Default::default(),
@@ -102,7 +102,7 @@ impl IfBlock {
// Parse conditions
let mut if_block = IfBlock {
key: key.into(),
key,
if_then: Default::default(),
default: Expression {
items: Default::default(),
@@ -214,7 +214,7 @@ impl IfBlock {
}
}
pub fn into_default(self, key: impl Into<CompactString>) -> IfBlock {
pub fn into_default(self, key: impl Into<String>) -> IfBlock {
IfBlock {
key: key.into(),
if_then: Default::default(),