Compare commits

..
2 changed files with 20 additions and 24 deletions
+13 -1
View File
@@ -246,6 +246,9 @@ fn point_fills(w: &mut W, s: &Series, g: Group) {
}
}
/// Data points (categories and values counted per series) one chart group writes to its caches.
const MAX_EXPORT_POINTS: usize = 4_000_000;
fn series(w: &mut W, c: &Chart, s: &Series, i: usize, kind: ChartType, g: Group) {
w.open0("c:ser");
w.val("c:idx", i);
@@ -529,7 +532,16 @@ fn plot_group(w: &mut W, c: &Chart, kind: ChartType, list: &[(usize, &Series)])
if g != Group::Stock {
w.val("c:varyColors", vary);
}
for (i, s) in list {
// Each series repeats the categories in its own cache, so the output grows with series times
// categories: stop adding series once a group's caches pass the budget (the first is always written).
let mut left = MAX_EXPORT_POINTS;
for (n, (i, s)) in list.iter().enumerate() {
let cost = c.categories.len().max(s.values.len()).saturating_mul(2).saturating_add(s.x_values.len() + s.sizes.len());
if n > 0 && cost > left {
log::warn!("pptx: chart export stopped after {n} series; the data caches passed {MAX_EXPORT_POINTS} points");
break;
}
left = left.saturating_sub(cost);
series(w, c, s, *i, kind, g);
}
if c.data_labels {
+7 -23
View File
@@ -61,23 +61,16 @@ pub fn missing(files: &[String], assets_md: &str) -> Vec<String> {
files.iter().filter(|f| is_asset(f) && !patterns.iter().any(|p| glob(p, f))).cloned().collect()
}
/// `*` matches any run of characters except `/`; everything else literally. Matched with a
/// table over the pattern, so a pattern with many `*` costs pattern length times name length
/// rather than exploring every way to split the name.
/// `*` matches any run of characters except `/`; everything else literally.
fn glob(pat: &str, s: &str) -> bool {
let t: Vec<char> = s.chars().collect();
// `row[k]`: the pattern so far matches the first k characters of the name.
let mut row = vec![false; t.len() + 1];
row[0] = true;
for pc in pat.chars() {
let mut next = vec![false; t.len() + 1];
next[0] = pc == '*' && row[0];
for k in 1..=t.len() {
next[k] = if pc == '*' { row[k] || (next[k - 1] && t[k - 1] != '/') } else { row[k - 1] && t[k - 1] == pc };
match pat.split_once('*') {
None => pat == s,
Some((head, tail)) => {
let Some(rest) = s.strip_prefix(head) else { return false };
let ends = rest.char_indices().map(|(i, _)| i).chain(std::iter::once(rest.len()));
ends.take_while(|&i| !rest[..i].contains('/')).any(|i| glob(tail, &rest[i..]))
}
row = next;
}
row[t.len()]
}
/// Splits `git ls-files -z` output into real file names (no display quoting of Unicode or special characters).
@@ -127,15 +120,6 @@ mod tests {
assert_eq!(missing(&["assets/é.png".into()], "`assets/*.svg`"), vec!["assets/é.png".to_string()]);
}
#[test]
fn many_wildcards_on_a_failing_name_finish_at_once() {
let pat = format!("{}b", "a*".repeat(40));
assert!(!glob(&pat, &"a".repeat(60)));
assert!(glob(&pat, &format!("{}b", "a".repeat(60))));
assert!(!glob("a*b", "a/b"));
assert!(glob("a*b", "ab"));
}
#[test]
fn ls_files_output_is_nul_separated_and_unquoted() {
let names = parse_ls_files("assets/zażółć.png\0docs/images/a b\nc.png\0".as_bytes());