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