mirror of
https://github.com/typst/typst
synced 2025-05-15 17:45:27 +08:00
Remove inline annotations in main crate
Inline annotations only have an effect cross-crate and LTO is enabled anyway. Benchmarks don't show any performance difference. Keeping them typst-syntax and typst-timing for now because these have a higher chance of being called cross-crate by crate consumers.
This commit is contained in:
parent
213bf36a05
commit
f57c34a7ce
@ -511,7 +511,6 @@ impl<'a> CapturesVisitor<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Capture a variable if it isn't internal.
|
/// Capture a variable if it isn't internal.
|
||||||
#[inline]
|
|
||||||
fn capture(
|
fn capture(
|
||||||
&mut self,
|
&mut self,
|
||||||
ident: &str,
|
ident: &str,
|
||||||
|
@ -72,25 +72,21 @@ pub struct Content(Arc<dyn NativeElement>);
|
|||||||
|
|
||||||
impl Content {
|
impl Content {
|
||||||
/// Creates a new content from an element.
|
/// Creates a new content from an element.
|
||||||
#[inline]
|
|
||||||
pub fn new<E: NativeElement>(elem: E) -> Self {
|
pub fn new<E: NativeElement>(elem: E) -> Self {
|
||||||
Self(Arc::new(elem))
|
Self(Arc::new(elem))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new empty sequence content.
|
/// Creates a new empty sequence content.
|
||||||
#[inline]
|
|
||||||
pub fn empty() -> Self {
|
pub fn empty() -> Self {
|
||||||
Self::new(SequenceElem::default())
|
Self::new(SequenceElem::default())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the element of this content.
|
/// Get the element of this content.
|
||||||
#[inline]
|
|
||||||
pub fn elem(&self) -> Element {
|
pub fn elem(&self) -> Element {
|
||||||
self.0.dyn_elem()
|
self.0.dyn_elem()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the span of the content.
|
/// Get the span of the content.
|
||||||
#[inline]
|
|
||||||
pub fn span(&self) -> Span {
|
pub fn span(&self) -> Span {
|
||||||
self.0.span()
|
self.0.span()
|
||||||
}
|
}
|
||||||
@ -102,7 +98,6 @@ impl Content {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get the label of the content.
|
/// Get the label of the content.
|
||||||
#[inline]
|
|
||||||
pub fn label(&self) -> Option<Label> {
|
pub fn label(&self) -> Option<Label> {
|
||||||
self.0.label()
|
self.0.label()
|
||||||
}
|
}
|
||||||
@ -154,7 +149,6 @@ impl Content {
|
|||||||
/// This is the preferred way to access fields. However, you can only use it
|
/// This is the preferred way to access fields. However, you can only use it
|
||||||
/// if you have set the field IDs yourself or are using the field IDs
|
/// if you have set the field IDs yourself or are using the field IDs
|
||||||
/// generated by the `#[elem]` macro.
|
/// generated by the `#[elem]` macro.
|
||||||
#[inline]
|
|
||||||
pub fn get(&self, id: u8) -> Option<Value> {
|
pub fn get(&self, id: u8) -> Option<Value> {
|
||||||
self.0.field(id)
|
self.0.field(id)
|
||||||
}
|
}
|
||||||
@ -163,7 +157,6 @@ impl Content {
|
|||||||
///
|
///
|
||||||
/// If you have access to the field IDs of the element, use [`Self::get`]
|
/// If you have access to the field IDs of the element, use [`Self::get`]
|
||||||
/// instead.
|
/// instead.
|
||||||
#[inline]
|
|
||||||
pub fn get_by_name(&self, name: &str) -> Option<Value> {
|
pub fn get_by_name(&self, name: &str) -> Option<Value> {
|
||||||
let id = self.elem().field_id(name)?;
|
let id = self.elem().field_id(name)?;
|
||||||
self.get(id)
|
self.get(id)
|
||||||
@ -174,7 +167,6 @@ impl Content {
|
|||||||
/// This is the preferred way to access fields. However, you can only use it
|
/// This is the preferred way to access fields. However, you can only use it
|
||||||
/// if you have set the field IDs yourself or are using the field IDs
|
/// if you have set the field IDs yourself or are using the field IDs
|
||||||
/// generated by the `#[elem]` macro.
|
/// generated by the `#[elem]` macro.
|
||||||
#[inline]
|
|
||||||
pub fn field(&self, id: u8) -> StrResult<Value> {
|
pub fn field(&self, id: u8) -> StrResult<Value> {
|
||||||
self.get(id)
|
self.get(id)
|
||||||
.ok_or_else(|| missing_field(self.elem().field_name(id).unwrap()))
|
.ok_or_else(|| missing_field(self.elem().field_name(id).unwrap()))
|
||||||
@ -185,7 +177,6 @@ impl Content {
|
|||||||
///
|
///
|
||||||
/// If you have access to the field IDs of the element, use [`Self::field`]
|
/// If you have access to the field IDs of the element, use [`Self::field`]
|
||||||
/// instead.
|
/// instead.
|
||||||
#[inline]
|
|
||||||
pub fn field_by_name(&self, name: &str) -> StrResult<Value> {
|
pub fn field_by_name(&self, name: &str) -> StrResult<Value> {
|
||||||
let id = self.elem().field_id(name).ok_or_else(|| missing_field(name))?;
|
let id = self.elem().field_id(name).ok_or_else(|| missing_field(name))?;
|
||||||
self.field(id)
|
self.field(id)
|
||||||
@ -415,7 +406,6 @@ impl Content {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Downcasts the element to the specified type.
|
/// Downcasts the element to the specified type.
|
||||||
#[inline]
|
|
||||||
pub fn to<T: NativeElement>(&self) -> Option<&T> {
|
pub fn to<T: NativeElement>(&self) -> Option<&T> {
|
||||||
// Early check for performance.
|
// Early check for performance.
|
||||||
if !self.is::<T>() {
|
if !self.is::<T>() {
|
||||||
@ -426,7 +416,6 @@ impl Content {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Downcasts mutably the element to the specified type.
|
/// Downcasts mutably the element to the specified type.
|
||||||
#[inline]
|
|
||||||
pub fn to_mut<T: NativeElement>(&mut self) -> Option<&mut T> {
|
pub fn to_mut<T: NativeElement>(&mut self) -> Option<&mut T> {
|
||||||
// Early check for performance.
|
// Early check for performance.
|
||||||
if !self.is::<T>() {
|
if !self.is::<T>() {
|
||||||
@ -437,7 +426,6 @@ impl Content {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Downcast the element into an owned value.
|
/// Downcast the element into an owned value.
|
||||||
#[inline]
|
|
||||||
pub fn unpack<T: NativeElement>(self) -> Option<Arc<T>> {
|
pub fn unpack<T: NativeElement>(self) -> Option<Arc<T>> {
|
||||||
// Early check for performance.
|
// Early check for performance.
|
||||||
if !self.is::<T>() {
|
if !self.is::<T>() {
|
||||||
@ -449,7 +437,6 @@ impl Content {
|
|||||||
|
|
||||||
/// Makes sure the content is not shared and returns a mutable reference to
|
/// Makes sure the content is not shared and returns a mutable reference to
|
||||||
/// the inner element.
|
/// the inner element.
|
||||||
#[inline]
|
|
||||||
fn make_mut(&mut self) -> &mut dyn NativeElement {
|
fn make_mut(&mut self) -> &mut dyn NativeElement {
|
||||||
let arc = &mut self.0;
|
let arc = &mut self.0;
|
||||||
if Arc::strong_count(arc) > 1 || Arc::weak_count(arc) > 0 {
|
if Arc::strong_count(arc) > 1 || Arc::weak_count(arc) > 0 {
|
||||||
|
@ -42,13 +42,11 @@ impl Label {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Resolves the label to a string.
|
/// Resolves the label to a string.
|
||||||
#[inline]
|
|
||||||
pub fn as_str(&self) -> &'static str {
|
pub fn as_str(&self) -> &'static str {
|
||||||
self.0.resolve()
|
self.0.resolve()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Turns this label into its inner interned string.
|
/// Turns this label into its inner interned string.
|
||||||
#[inline]
|
|
||||||
pub fn into_inner(self) -> PicoStr {
|
pub fn into_inner(self) -> PicoStr {
|
||||||
self.0
|
self.0
|
||||||
}
|
}
|
||||||
|
@ -980,13 +980,11 @@ pub(super) fn is_gb_style(lang: Lang, region: Option<Region>) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Whether the glyph is a space.
|
/// Whether the glyph is a space.
|
||||||
#[inline]
|
|
||||||
fn is_space(c: char) -> bool {
|
fn is_space(c: char) -> bool {
|
||||||
matches!(c, ' ' | '\u{00A0}' | ' ')
|
matches!(c, ' ' | '\u{00A0}' | ' ')
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Whether the glyph is part of Chinese or Japanese script (i.e. CJ, not CJK).
|
/// Whether the glyph is part of Chinese or Japanese script (i.e. CJ, not CJK).
|
||||||
#[inline]
|
|
||||||
pub(super) fn is_of_cj_script(c: char) -> bool {
|
pub(super) fn is_of_cj_script(c: char) -> bool {
|
||||||
is_cj_script(c, c.script())
|
is_cj_script(c, c.script())
|
||||||
}
|
}
|
||||||
@ -994,7 +992,6 @@ pub(super) fn is_of_cj_script(c: char) -> bool {
|
|||||||
/// Whether the glyph is part of Chinese or Japanese script (i.e. CJ, not CJK).
|
/// Whether the glyph is part of Chinese or Japanese script (i.e. CJ, not CJK).
|
||||||
/// The function is dedicated to typesetting Chinese or Japanese, which do not
|
/// The function is dedicated to typesetting Chinese or Japanese, which do not
|
||||||
/// have spaces between words, so K is not checked here.
|
/// have spaces between words, so K is not checked here.
|
||||||
#[inline]
|
|
||||||
fn is_cj_script(c: char, script: Script) -> bool {
|
fn is_cj_script(c: char, script: Script) -> bool {
|
||||||
use Script::*;
|
use Script::*;
|
||||||
// U+30FC: Katakana-Hiragana Prolonged Sound Mark
|
// U+30FC: Katakana-Hiragana Prolonged Sound Mark
|
||||||
@ -1002,7 +999,6 @@ fn is_cj_script(c: char, script: Script) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// See <https://www.w3.org/TR/clreq/#punctuation_width_adjustment>
|
/// See <https://www.w3.org/TR/clreq/#punctuation_width_adjustment>
|
||||||
#[inline]
|
|
||||||
fn is_cjk_left_aligned_punctuation(
|
fn is_cjk_left_aligned_punctuation(
|
||||||
c: char,
|
c: char,
|
||||||
x_advance: Em,
|
x_advance: Em,
|
||||||
@ -1027,7 +1023,6 @@ fn is_cjk_left_aligned_punctuation(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// See <https://www.w3.org/TR/clreq/#punctuation_width_adjustment>
|
/// See <https://www.w3.org/TR/clreq/#punctuation_width_adjustment>
|
||||||
#[inline]
|
|
||||||
fn is_cjk_right_aligned_punctuation(
|
fn is_cjk_right_aligned_punctuation(
|
||||||
c: char,
|
c: char,
|
||||||
x_advance: Em,
|
x_advance: Em,
|
||||||
@ -1043,7 +1038,6 @@ fn is_cjk_right_aligned_punctuation(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// See <https://www.w3.org/TR/clreq/#punctuation_width_adjustment>
|
/// See <https://www.w3.org/TR/clreq/#punctuation_width_adjustment>
|
||||||
#[inline]
|
|
||||||
fn is_cjk_center_aligned_punctuation(c: char, gb_style: bool) -> bool {
|
fn is_cjk_center_aligned_punctuation(c: char, gb_style: bool) -> bool {
|
||||||
if !gb_style && matches!(c, ',' | '。' | '.' | '、' | ':' | ';') {
|
if !gb_style && matches!(c, ',' | '。' | '.' | '、' | ':' | ';') {
|
||||||
return true;
|
return true;
|
||||||
@ -1060,7 +1054,6 @@ fn is_cjk_center_aligned_punctuation(c: char, gb_style: bool) -> bool {
|
|||||||
/// fullwidth. This heuristics can therefore fail for monospace latin fonts.
|
/// fullwidth. This heuristics can therefore fail for monospace latin fonts.
|
||||||
/// However, since monospace fonts are usually not justified this edge case
|
/// However, since monospace fonts are usually not justified this edge case
|
||||||
/// should be rare enough.
|
/// should be rare enough.
|
||||||
#[inline]
|
|
||||||
fn is_justifiable(
|
fn is_justifiable(
|
||||||
c: char,
|
c: char,
|
||||||
script: Script,
|
script: Script,
|
||||||
|
@ -32,7 +32,6 @@ impl Scalar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the value of this [`Scalar`].
|
/// Gets the value of this [`Scalar`].
|
||||||
#[inline]
|
|
||||||
pub const fn get(self) -> f64 {
|
pub const fn get(self) -> f64 {
|
||||||
self.0
|
self.0
|
||||||
}
|
}
|
||||||
|
@ -1173,7 +1173,6 @@ impl Color {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Converts a 32-bit integer to an RGBA color.
|
/// Converts a 32-bit integer to an RGBA color.
|
||||||
#[inline]
|
|
||||||
pub fn from_u32(color: u32) -> Self {
|
pub fn from_u32(color: u32) -> Self {
|
||||||
Self::from_u8(
|
Self::from_u8(
|
||||||
((color >> 24) & 0xFF) as u8,
|
((color >> 24) & 0xFF) as u8,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user