mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
More EcoVec usage
Frame unfortunately can't use it because splice is missing.
This commit is contained in:
parent
a1d47695a2
commit
457ce95436
@ -1,5 +1,6 @@
|
|||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
use ecow::EcoVec;
|
||||||
use typst::model::Regex;
|
use typst::model::Regex;
|
||||||
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
@ -275,7 +276,7 @@ castable! {
|
|||||||
/// construct
|
/// construct
|
||||||
#[func]
|
#[func]
|
||||||
pub fn symbol(args: &mut Args) -> SourceResult<Value> {
|
pub fn symbol(args: &mut Args) -> SourceResult<Value> {
|
||||||
let mut list: Vec<(EcoString, char)> = vec![];
|
let mut list = EcoVec::new();
|
||||||
for Spanned { v, span } in args.all::<Spanned<Variant>>()? {
|
for Spanned { v, span } in args.all::<Spanned<Variant>>()? {
|
||||||
if list.iter().any(|(prev, _)| &v.0 == prev) {
|
if list.iter().any(|(prev, _)| &v.0 == prev) {
|
||||||
bail!(span, "duplicate variant");
|
bail!(span, "duplicate variant");
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
use std::fmt::{self, Debug, Formatter, Write};
|
use std::fmt::{self, Debug, Formatter, Write};
|
||||||
|
|
||||||
|
use ecow::EcoVec;
|
||||||
|
|
||||||
use super::{Array, Cast, Dict, Str, Value};
|
use super::{Array, Cast, Dict, Str, Value};
|
||||||
use crate::diag::{bail, At, SourceResult};
|
use crate::diag::{bail, At, SourceResult};
|
||||||
use crate::syntax::{Span, Spanned};
|
use crate::syntax::{Span, Spanned};
|
||||||
@ -10,7 +12,7 @@ pub struct Args {
|
|||||||
/// The span of the whole argument list.
|
/// The span of the whole argument list.
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
/// The positional and named arguments.
|
/// The positional and named arguments.
|
||||||
pub items: Vec<Arg>,
|
pub items: EcoVec<Arg>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An argument to a function call: `12` or `draw: false`.
|
/// An argument to a function call: `12` or `draw: false`.
|
||||||
|
@ -6,9 +6,8 @@ use std::ops::{Add, AddAssign};
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use comemo::Tracked;
|
use comemo::Tracked;
|
||||||
use ecow::EcoString;
|
use ecow::{EcoString, EcoVec};
|
||||||
use siphasher::sip128::{Hasher128, SipHasher};
|
use siphasher::sip128::{Hasher128, SipHasher};
|
||||||
use thin_vec::ThinVec;
|
|
||||||
use typst_macros::node;
|
use typst_macros::node;
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
@ -25,7 +24,7 @@ use crate::World;
|
|||||||
pub struct Content {
|
pub struct Content {
|
||||||
obj: Arc<dyn Bounds>,
|
obj: Arc<dyn Bounds>,
|
||||||
span: Option<Span>,
|
span: Option<Span>,
|
||||||
modifiers: ThinVec<Modifier>,
|
modifiers: EcoVec<Modifier>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Modifiers that can be attached to content.
|
/// Modifiers that can be attached to content.
|
||||||
@ -68,9 +67,9 @@ impl Content {
|
|||||||
|
|
||||||
/// Attach a label to the content.
|
/// Attach a label to the content.
|
||||||
pub fn labelled(mut self, label: Label) -> Self {
|
pub fn labelled(mut self, label: Label) -> Self {
|
||||||
for modifier in &mut self.modifiers {
|
for (i, modifier) in self.modifiers.iter().enumerate() {
|
||||||
if let Modifier::Label(prev) = modifier {
|
if matches!(modifier, Modifier::Label(_)) {
|
||||||
*prev = label;
|
self.modifiers.make_mut()[i] = Modifier::Label(label);
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -408,7 +407,7 @@ pub trait Node: 'static + Capable {
|
|||||||
Content {
|
Content {
|
||||||
obj: Arc::new(self),
|
obj: Arc::new(self),
|
||||||
span: None,
|
span: None,
|
||||||
modifiers: ThinVec::new(),
|
modifiers: EcoVec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1033,7 +1033,7 @@ impl Eval for ast::Args {
|
|||||||
type Output = Args;
|
type Output = Args;
|
||||||
|
|
||||||
fn eval(&self, vm: &mut Vm) -> SourceResult<Self::Output> {
|
fn eval(&self, vm: &mut Vm) -> SourceResult<Self::Output> {
|
||||||
let mut items = Vec::new();
|
let mut items = EcoVec::new();
|
||||||
|
|
||||||
for arg in self.items() {
|
for arg in self.items() {
|
||||||
let span = arg.span();
|
let span = arg.span();
|
||||||
|
@ -115,7 +115,7 @@ impl Func {
|
|||||||
Repr::Native(native) => (native.func)(vm, &mut args)?,
|
Repr::Native(native) => (native.func)(vm, &mut args)?,
|
||||||
Repr::Closure(closure) => closure.call(vm, self, &mut args)?,
|
Repr::Closure(closure) => closure.call(vm, self, &mut args)?,
|
||||||
Repr::With(wrapped, applied) => {
|
Repr::With(wrapped, applied) => {
|
||||||
args.items.splice(..0, applied.items.iter().cloned());
|
args.items = applied.items.iter().cloned().chain(args.items).collect();
|
||||||
return wrapped.call(vm, args);
|
return wrapped.call(vm, args);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
use std::cmp::Reverse;
|
use std::cmp::Reverse;
|
||||||
use std::collections::BTreeSet;
|
use std::collections::BTreeSet;
|
||||||
use std::fmt::{self, Debug, Display, Formatter, Write};
|
use std::fmt::{self, Debug, Display, Formatter, Write};
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
use ecow::EcoString;
|
use ecow::{EcoString, EcoVec};
|
||||||
|
|
||||||
use crate::diag::StrResult;
|
use crate::diag::StrResult;
|
||||||
|
|
||||||
@ -22,7 +21,7 @@ pub struct Symbol {
|
|||||||
enum Repr {
|
enum Repr {
|
||||||
Single(char),
|
Single(char),
|
||||||
Static(&'static [(&'static str, char)]),
|
Static(&'static [(&'static str, char)]),
|
||||||
Runtime(Arc<Vec<(EcoString, char)>>),
|
Runtime(EcoVec<(EcoString, char)>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Symbol {
|
impl Symbol {
|
||||||
@ -43,10 +42,10 @@ impl Symbol {
|
|||||||
|
|
||||||
/// Create a symbol with a runtime variant list.
|
/// Create a symbol with a runtime variant list.
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
pub fn runtime(list: Vec<(EcoString, char)>) -> Self {
|
pub fn runtime(list: EcoVec<(EcoString, char)>) -> Self {
|
||||||
debug_assert!(!list.is_empty());
|
debug_assert!(!list.is_empty());
|
||||||
Self {
|
Self {
|
||||||
repr: Repr::Runtime(Arc::new(list)),
|
repr: Repr::Runtime(list),
|
||||||
modifiers: EcoString::new(),
|
modifiers: EcoString::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user