mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-27 04:38:49 +00:00
Keep memo token comparison within style
This commit is contained in:
@@ -227,11 +227,11 @@ pub(crate) fn line_baseline(ctx: &Context, env: &TextEnv<'_>, role: TypeRole, ce
|
||||
}
|
||||
|
||||
/// A bounded per-context cache. Equality compares the complete input, rather than trusting a hash collision.
|
||||
#[derive(Clone, PartialEq)]
|
||||
#[derive(Clone)]
|
||||
struct LayoutKey {
|
||||
run: TextRun<'static>,
|
||||
tokens: u64,
|
||||
token_values: Arc<craft_theme::Tokens>,
|
||||
token_values: UiTokens,
|
||||
direction: Direction,
|
||||
ink: Color32,
|
||||
fonts: StackFacts,
|
||||
@@ -243,7 +243,7 @@ struct LayoutKey {
|
||||
struct LayoutQuery<'a> {
|
||||
run: &'a TextRun<'a>,
|
||||
tokens: u64,
|
||||
token_values: &'a Arc<craft_theme::Tokens>,
|
||||
token_values: &'a UiTokens,
|
||||
direction: Direction,
|
||||
ink: Color32,
|
||||
fonts: StackFacts,
|
||||
@@ -298,7 +298,7 @@ impl LayoutQuery<'_> {
|
||||
fn matches(&self, key: &LayoutKey) -> bool {
|
||||
key.run == *self.run
|
||||
&& key.tokens == self.tokens
|
||||
&& (Arc::ptr_eq(&key.token_values, self.token_values) || key.token_values.as_ref() == self.token_values.as_ref())
|
||||
&& key.token_values.same_source_tokens(self.token_values)
|
||||
&& key.direction == self.direction
|
||||
&& key.ink == self.ink
|
||||
&& key.fonts == self.fonts
|
||||
@@ -334,7 +334,7 @@ impl LayoutQuery<'_> {
|
||||
rotation: self.run.rotation,
|
||||
},
|
||||
tokens: self.tokens,
|
||||
token_values: Arc::clone(self.token_values),
|
||||
token_values: self.token_values.clone(),
|
||||
direction: self.direction,
|
||||
ink: self.ink,
|
||||
fonts: self.fonts,
|
||||
@@ -385,7 +385,7 @@ impl TextRun<'_> {
|
||||
LayoutQuery {
|
||||
run: self,
|
||||
tokens: env.tokens.key(),
|
||||
token_values: env.tokens.tokens(),
|
||||
token_values: env.tokens,
|
||||
direction: env.direction,
|
||||
ink: env.ink,
|
||||
fonts: env.fonts,
|
||||
|
||||
@@ -80,6 +80,11 @@ impl UiTokens {
|
||||
&self.tokens
|
||||
}
|
||||
|
||||
/// Whether the resolved source tokens used by text layout are equal.
|
||||
pub(crate) fn same_source_tokens(&self, other: &Self) -> bool {
|
||||
Arc::ptr_eq(&self.tokens, &other.tokens) || self.tokens == other.tokens
|
||||
}
|
||||
|
||||
/// The theme's token-group values.
|
||||
pub fn groups(&self) -> &GroupValues {
|
||||
&self.groups
|
||||
|
||||
Reference in New Issue
Block a user