/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
//! Code related to the invalidation of media-query-affected rules.
/// A key for a given media query result. /// /// NOTE: It happens to be the case that all the media lists we care about /// happen to have a stable address, so we can just use an opaque pointer to /// represent them. /// /// Also, note that right now when a rule or stylesheet is removed, we do a full /// style flush, so there's no need to worry about other item created with the /// same pointer address. /// /// If this changes, though, we may need to remove the item from the cache if /// present before it goes away. #[derive(Clone, Copy, Debug, Eq, Hash, MallocSizeOf, PartialEq)] pubstruct MediaListKey(usize);
impl MediaListKey { /// Create a MediaListKey from a raw usize. pubfn from_raw(k: usize) -> Self {
MediaListKey(k)
}
}
/// A trait to get a given `MediaListKey` for a given item that can hold a /// `MediaList`. pubtrait ToMediaListKey: Sized { /// Get a `MediaListKey` for this item. This key needs to uniquely identify /// the item. fn to_media_list_key(&self) -> MediaListKey {
MediaListKey(selfas *constSelfas usize)
}
}
impl ToMediaListKey for StylesheetContents {} impl ToMediaListKey for ImportRule {} impl ToMediaListKey for MediaRule {}
/// A struct that holds the result of a media query evaluation pass for the /// media queries that evaluated successfully. #[derive(Clone, Debug, MallocSizeOf, PartialEq)] pubstruct EffectiveMediaQueryResults { /// The set of media lists that matched last time.
set: FxHashSet<MediaListKey>,
}
/// Resets the results, using an empty key. pubfn clear(&mutself) { self.set.clear()
}
/// Returns whether a given item was known to be effective when the results /// were cached. pubfn was_effective<T>(&self, item: &T) -> bool where
T: ToMediaListKey,
{ self.set.contains(&item.to_media_list_key())
}
/// Notices that an effective item has been seen, and caches it as matching. pubfn saw_effective<T>(&mutself, item: &T) where
T: ToMediaListKey,
{ // NOTE(emilio): We can't assert that we don't cache the same item twice // because of stylesheet reusing... shrug. self.set.insert(item.to_media_list_key());
}
}
/// A filter that filters over effective rules, but allowing all potentially /// effective `@media` rules. pubstruct PotentiallyEffectiveMediaRules;
/// Whether we should process the nested rules in a given `@-moz-document` rule. fn process_document(
guard: &SharedRwLockReadGuard,
device: &Device,
quirks_mode: QuirksMode,
rule: &DocumentRule,
) -> bool { usecrate::stylesheets::EffectiveRules;
EffectiveRules::process_document(guard, device, quirks_mode, rule)
}
/// Whether we should process the nested rules in a given `@supports` rule. fn process_supports(
guard: &SharedRwLockReadGuard,
device: &Device,
quirks_mode: QuirksMode,
rule: &SupportsRule,
) -> bool { usecrate::stylesheets::EffectiveRules;
EffectiveRules::process_supports(guard, device, quirks_mode, rule)
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.11 Sekunden
(vorverarbeitet am 2026-06-19)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.