Skip to main content

RuleIndex

Struct RuleIndex 

Source
pub struct RuleIndex {
Show 21 fields by_id: IndexMap<String, Vec<usize>, BuildHasherDefault<FnvHasher>>, by_class: IndexMap<String, Vec<usize>, BuildHasherDefault<FnvHasher>>, by_tag: IndexMap<String, Vec<usize>, BuildHasherDefault<FnvHasher>>, by_attr: IndexMap<String, Vec<usize>, BuildHasherDefault<FnvHasher>>, all_attr_rules: Vec<usize>, ancestor_reqs: Vec<AncReqs>, ancestor_starts: Vec<u32>, universal: Vec<usize>, rule_count: usize, state_masks: Vec<u8>, full_siblings: bool, sib_left: IndexMap<String, Vec<usize>, BuildHasherDefault<FnvHasher>>, sib_left_any: bool, anc_pos: IndexMap<String, Vec<usize>, BuildHasherDefault<FnvHasher>>, anc_pos_any: bool, anc_sib: IndexMap<String, Vec<usize>, BuildHasherDefault<FnvHasher>>, anc_sib_any: bool, anc_empty: IndexMap<String, Vec<usize>, BuildHasherDefault<FnvHasher>>, anc_empty_any: bool, referenced_attrs: BTreeSet<String>, any_state_masks: u8,
}
Expand description

スタイルシート内のルールを右端キーで振り分けた索引。 保持するのは元の rules スライスに対する添字のみで、ルール本体は複製しない。

Fields§

§by_id: IndexMap<String, Vec<usize>, BuildHasherDefault<FnvHasher>>§by_class: IndexMap<String, Vec<usize>, BuildHasherDefault<FnvHasher>>§by_tag: IndexMap<String, Vec<usize>, BuildHasherDefault<FnvHasher>>§by_attr: IndexMap<String, Vec<usize>, BuildHasherDefault<FnvHasher>>

右端が属性だけ([dark] 等。id/class/tag 無し)の規則を、最初の属性名で振り分けたもの。

§all_attr_rules: Vec<usize>

by_attr の全規則(昇順・重複なし)。属性を渡さない問い合わせで取りこぼさないために使う。

§ancestor_reqs: Vec<AncReqs>

規則ごと・セレクタごとの「祖先に必要な特徴」のハッシュ(AncestorBloom で照合前に枝刈り)。 全規則のセレクタの分を平らに並べ、規則 r の分は ancestor_starts[r]..ancestor_starts[r + 1]。

§ancestor_starts: Vec<u32>§universal: Vec<usize>§rule_count: usize§state_masks: Vec<u8>

ルールごとの動的疑似クラス使用ビット(bit0=hover, bit1=focus, bit2=active)。

「そのルールが :hover を使うか」はノードに依存しない。 以前はカスケードがノードごとに候補ルール全部へ rule_uses_state を 呼んでおり、同じ答えを N×C 回計算し直していた。 索引を作るのと同じ 1 回の走査で求めておく。

§full_siblings: bool

右端以外のコンパウンドが兄弟全員の中身に依存する規則がある(使い回しの鍵に常に兄弟全員の特徴を入れる)。

§sib_left: IndexMap<String, Vec<usize>, BuildHasherDefault<FnvHasher>>

+・~ の左側のコンパウンドの id・class・タグ(使い回しの鍵に前の兄弟の特徴を入れるかの判定。sibling_relevant)。

§sib_left_any: bool

+・~ の左側に id・class・タグで絞れないコンパウンドがある(前の兄弟の特徴を常に入れる)。

§anc_pos: IndexMap<String, Vec<usize>, BuildHasherDefault<FnvHasher>>

右端以外で位置(:first-child 等)や前の兄弟(+・~ の右側)に依存するコンパウンドの id・class・タグ (子孫へ渡す使い回しの鍵に、祖先の位置と兄弟の文脈を入れるかの判定。ancestor_ctx_relevant)。 3 種(位置・前の兄弟〔+・~ の右側〕・子の有無〔:empty〕)それぞれの表と「絞れないものがある」。

§anc_pos_any: bool§anc_sib: IndexMap<String, Vec<usize>, BuildHasherDefault<FnvHasher>>§anc_sib_any: bool§anc_empty: IndexMap<String, Vec<usize>, BuildHasherDefault<FnvHasher>>§anc_empty_any: bool§referenced_attrs: BTreeSet<String>

スタイルシート内の全セレクタ(:not() / :is() / :where() / :has() 内や左側の段を含む)に 現れる属性名の集合(小文字)。JS が setAttribute / removeAttribute した属性が ここに無く、かつ HTML の固有表示属性でもなければ、スタイル計算の結果は一切変わらない(TODO P4b)。

§any_state_masks: u8

全ルールの state_masks のビット論理和(:has() や動的疑似クラスがシート内に 1 つでも存在するか O(1) 判定用)。

Implementations§

Source§

impl RuleIndex

Source

pub fn sibling_relevant(&self, n: &Node) -> bool

前の兄弟 n の特徴が、後ろの兄弟(とその子孫)のスタイルに効き得るか(+・~ の左側に一致し得るか)。 効かない兄弟は使い回しの鍵に種類(タグ)だけを入れる。

Source

pub fn ancestor_needs(&self, n: &Node) -> AncestorNeeds

祖先 n の位置・兄弟の文脈・子の有無のうち、子孫のスタイルに効き得るもの(右端以外の :first-child・+ の右側・ :empty に一致し得るか)。効かないものは子孫へ渡す鍵に入れない。

Source

fn may_match_keys( map: &IndexMap<String, Vec<usize>, BuildHasherDefault<FnvHasher>>, any: bool, n: &Node, ) -> bool

Source

pub fn needs_full_siblings(&self) -> bool

使い回しの鍵に常に兄弟全員の特徴を入れる必要があるか(STATE_SIB_ALL の祖先版)。

Source

pub fn states_of(&self, cands: &[usize]) -> Option<u8>

与えられた候補ルール群が使う動的疑似クラスのビットを OR して返す。

範囲外の添字が混ざっていたら None。呼び出し側は 「全状態を計算する」へフォールバックする(取りこぼしより遅い方を選ぶ)。

計算量: O(C)。

【2026-08-05】グローバルの ACTIVE を介さずに問い合わせられるよう、 active_states_of から本体をこちらへ移した。 試験がグローバル状態に依存していたため、並列実行される他の試験が clear_active() した瞬間に None が返って落ちていた (実測: 8 回に 1 回程度。spec/logging_policy.md T-1 の再発)。 索引そのものの性質は索引だけで確かめられる。

Source

pub fn build(rules: &[Rule]) -> Self

ルール列から索引を構築する。

1 ルールが複数セレクタ(a, b, c)を持つ場合、いずれかのセレクタが マッチすればそのルールは適用対象なので、全セレクタのキーへ登録する。

Source

pub fn uses_attr(&self, name_lower: &str) -> bool

スタイルシート内のいずれかのセレクタがこの属性名(小文字)を参照しているか(TODO P4b)。

Source

pub fn referenced_attrs(&self) -> &BTreeSet<String>

スタイルシート内のセレクタが参照している全属性名(小文字)の集合。

Source

pub fn ancestors_may_match( &self, rule: usize, sel: usize, bloom: &AncestorBloom, ) -> bool

規則 rule のセレクタ sel が、祖先の特徴 bloom の下で一致し得るか。 false なら確実に一致しない(祖先に必要な id/class/tag が無い)。不明なときは true。

Source

pub fn any_state_masks(&self) -> u8

索引が対象としているルール総数。 スタイルシート内の全ルールの state_masks の論理和(STATE_* ビット)。

Source

pub fn rule_count(&self) -> usize

索引が対象としているルール総数。

Source

pub fn universal_count(&self) -> usize

常時照合が必要な(絞り込めなかった)ルール数。 これが総数に近いほど索引の効果は薄い。

Source

pub fn candidates_into( &self, tag: &str, id: Option<&str>, classes: &[String], out: &mut Vec<usize>, ) -> Result<(), IndexError>

ある要素について照合すべきルールの添字を昇順・重複なしで out バッファへ格納する。 昇順なのはカスケードの後勝ち規則(同特異度なら後のルールが勝つ)を 元の宣言順のまま保つため。バッファを再利用することでヒープ確保をゼロ化する。

Source

pub fn candidates_into_with_attrs<'b, I>( &self, tag: &str, id: Option<&str>, classes: &[String], attr_names: I, out: &mut Vec<usize>, ) -> Result<(), IndexError>
where I: IntoIterator<Item = &'b str>,

candidates_into に要素の属性名を加えた版。属性だけの規則は、要素が持つ属性名の バケットだけを候補にする(カスケードはこちらを使う)。

Source

pub fn candidates_with_attrs( &self, tag: &str, id: Option<&str>, classes: &[String], attr_names: &[String], ) -> Result<Vec<usize>, IndexError>

candidates_into_with_attrs の Vec を返す版(試験用)。

Source

fn extend_keyed( &self, tag: &str, id: Option<&str>, classes: &[String], out: &mut Vec<usize>, )

id・クラス・タグのバケットを out へ足す(並べ替え・重複除去は呼び出し側)。

Source

pub fn candidates( &self, tag: &str, id: Option<&str>, classes: &[String], ) -> Result<Vec<usize>, IndexError>

ある要素について照合すべきルールの添字を昇順・重複なしで返す。 昇順なのはカスケードの後勝ち規則(同特異度なら後のルールが勝つ)を 元の宣言順のまま保つため。

引数が不正(タグ名が空)なときは黙って戻らず、エラーログを出して Err を返す。 呼び出し側は「全ルールを照合する」従来動作へフォールバックすること (絞り込みを誤って描画が欠けるより、遅くても正しい方を選ぶ)。

Trait Implementations§

Source§

impl Debug for RuleIndex

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for RuleIndex

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.