mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
Remove uses of EcoString::inline
EcoString::inline can produce runtime panics if things are changed later. It should only be used if really necessary (because of const context)
This commit is contained in:
parent
67ead94cc2
commit
0c08022ffa
@ -837,13 +837,7 @@ fn create_native_elem_impl(element: &Elem) -> TokenStream {
|
|||||||
let field_dict = element.inherent_fields().clone().map(|field| {
|
let field_dict = element.inherent_fields().clone().map(|field| {
|
||||||
let name = &field.name;
|
let name = &field.name;
|
||||||
let field_ident = &field.ident;
|
let field_ident = &field.ident;
|
||||||
|
let field_call = quote! { ::ecow::EcoString::from(#name).into() };
|
||||||
let field_call = if name.len() > 15 {
|
|
||||||
quote! { ::ecow::EcoString::from(#name).into() }
|
|
||||||
} else {
|
|
||||||
quote! { ::ecow::EcoString::inline(#name).into() }
|
|
||||||
};
|
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
fields.insert(
|
fields.insert(
|
||||||
#field_call,
|
#field_call,
|
||||||
@ -860,13 +854,7 @@ fn create_native_elem_impl(element: &Elem) -> TokenStream {
|
|||||||
.map(|field| {
|
.map(|field| {
|
||||||
let name = &field.name;
|
let name = &field.name;
|
||||||
let field_ident = &field.ident;
|
let field_ident = &field.ident;
|
||||||
|
let field_call = quote! { ::ecow::EcoString::from(#name).into() };
|
||||||
let field_call = if name.len() > 15 {
|
|
||||||
quote! { ::ecow::EcoString::from(#name).into() }
|
|
||||||
} else {
|
|
||||||
quote! { ::ecow::EcoString::inline(#name).into() }
|
|
||||||
};
|
|
||||||
|
|
||||||
if field.synthesized && field.default.is_some() {
|
if field.synthesized && field.default.is_some() {
|
||||||
quote! {
|
quote! {
|
||||||
fields.insert(
|
fields.insert(
|
||||||
@ -926,7 +914,7 @@ fn create_native_elem_impl(element: &Elem) -> TokenStream {
|
|||||||
quote! {
|
quote! {
|
||||||
if let Some(label) = self.label() {
|
if let Some(label) = self.label() {
|
||||||
fields.insert(
|
fields.insert(
|
||||||
::ecow::EcoString::inline("label").into(),
|
"label".into(),
|
||||||
#foundations::IntoValue::into_value(label)
|
#foundations::IntoValue::into_value(label)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -695,11 +695,8 @@ impl Serialize for Content {
|
|||||||
S: Serializer,
|
S: Serializer,
|
||||||
{
|
{
|
||||||
serializer.collect_map(
|
serializer.collect_map(
|
||||||
iter::once((
|
iter::once(("func".into(), self.func().name().into_value()))
|
||||||
Str::from(EcoString::inline("func")),
|
.chain(self.fields()),
|
||||||
self.func().name().into_value(),
|
|
||||||
))
|
|
||||||
.chain(self.fields()),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -736,7 +733,7 @@ impl PartialEq for SequenceElem {
|
|||||||
impl Repr for SequenceElem {
|
impl Repr for SequenceElem {
|
||||||
fn repr(&self) -> EcoString {
|
fn repr(&self) -> EcoString {
|
||||||
if self.children.is_empty() {
|
if self.children.is_empty() {
|
||||||
EcoString::inline("[]")
|
"[]".into()
|
||||||
} else {
|
} else {
|
||||||
eco_format!(
|
eco_format!(
|
||||||
"[{}]",
|
"[{}]",
|
||||||
|
@ -7,7 +7,7 @@ pub struct SpaceElem {}
|
|||||||
|
|
||||||
impl Repr for SpaceElem {
|
impl Repr for SpaceElem {
|
||||||
fn repr(&self) -> EcoString {
|
fn repr(&self) -> EcoString {
|
||||||
EcoString::inline("[ ]")
|
"[ ]".into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user