1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//! The work rendering does, counted where tests read it to check how it grows with the content.
/// A kind of work rendering does.
#[derive(Clone, Copy)]
pub(crate) enum Work {
/// An SVG element converting, inside measurements included.
Conversion,
/// A node a walk over an SVG tree and its resources visits.
Visit,
/// A byte of SVG text the shaper shapes.
ShapedByte,
/// A span an SVG text chunk built from another holds.
HeldSpan,
/// An SVG text character whose code point position is recorded or looked up.
CodePoint,
/// A character advance summed while hiding an overflowing SVG text line's characters.
HiddenAdvance,
/// The offset of a tile whose overflowing content a pattern tile shows.
OverflowTile,
/// A parent link followed while counting the inline boxes in each box's subtree.
BoxAncestor,
/// A text span a search for the span at an offset of a paragraph compares.
SpanProbe,
/// An ancestor selector matching, or the ancestor filter of the element it matches, steps to.
SelectorAncestor,
/// An open formatting frame a lookup on behalf of the element being formatted reads.
OpenFrame,
/// A node a style evaluation looks up among those it has open, to find dependency cycles.
ActiveNode,
/// A counter that work on an element's counters steps over, as the counter budget charges.
CounterStep,
/// A step of a paint order path that placing a retained lane's paints in the enclosing
/// traversal copies.
PlacedStep,
/// A run of text the shaper shapes.
ShapedRun,
/// A shape plan made for a face.
ShapePlan,
/// A font list matched against the faces of a font book.
FontListMatch,
/// A character whose script is looked up to split text into runs of one script.
ScriptCharacter,
/// A blurred shadow mask rasterized.
ShadowMask,
/// A style rule whose selectors are tried against an element or one of its
/// pseudo-elements.
RuleCandidate,
/// A pseudo-element whose style computes.
PseudoStyle,
/// A user-agent style sheet parsed and prepared.
UserAgentSheet,
/// A style the cascade computes for an element or pseudo-element.
ComputedStyle,
/// A scan of a set of font folders for installed fonts.
#[cfg(file_system)]
FontScan,
/// A byte of a font file that a scan for installed fonts reads.
#[cfg(file_system)]
FontScanBytes,
/// A child of a box that a walk over its children, for the semantic events after one of
/// them, steps over.
SiblingStep,
/// A track or item that sizing a grid's tracks to the items spanning one track steps over.
SingleSpanStep,
/// A fragmentainer that walks from a position in a row to offsets below it, such as its
/// rows and its collapsed cells or items, visit.
BandPage,
/// A flex or grid item measured or laid out rather than taken from those kept.
ItemMeasurement,
/// A box whose min- and max-content widths are computed rather than taken from those
/// kept.
ContentSizes,
}
#[cfg(test)]
const KINDS: usize = 30;
#[cfg(test)]
thread_local! {
static COUNTS: std::cell::Cell<[usize; KINDS]> = const { std::cell::Cell::new([0; KINDS]) };
}
/// Counts `units` of `work`.
#[inline]
pub(crate) fn count(work: Work, units: usize) {
#[cfg(test)]
COUNTS.with(|counts| {
let mut all = counts.get();
all[work as usize] += units;
counts.set(all);
});
#[cfg(not(test))]
let _ = (work, units);
}
/// What `run` returns, with the units of `work` it did on this thread.
#[cfg(test)]
pub(crate) fn measured<T>(work: Work, run: impl FnOnce() -> T) -> (T, usize) {
let before = COUNTS.with(std::cell::Cell::get)[work as usize];
let output = run();
(
output,
COUNTS.with(std::cell::Cell::get)[work as usize] - before,
)
}
/// Asserts that the work `measure` counts for content of `size`, and of twice that, grows
/// linearly; `what` names the content.
#[cfg(test)]
pub(crate) fn assert_linear(what: &str, size: usize, measure: impl Fn(usize) -> usize) {
const GROWTH: f64 = 2.2;
let [single, double] = [size, 2 * size].map(measure);
assert!(
single > 0 && double as f64 <= GROWTH * single as f64,
"{what}: {single} units of work for {size}, {double} for {}, more than {GROWTH} times \
as many",
2 * size
);
}