From ba087cdbbb6e1661d65e92a7cf4f567b9054f02d Mon Sep 17 00:00:00 2001 From: Max Gietl <> Date: Wed, 20 Nov 2024 15:50:46 +0100 Subject: [PATCH] fix unnecessary disambiguation by checking ambiguity on a render with ibids disabled --- src/csl/mod.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/csl/mod.rs b/src/csl/mod.rs index a366f75f..8208edca 100644 --- a/src/csl/mod.rs +++ b/src/csl/mod.rs @@ -56,6 +56,7 @@ impl Default for BibliographyDriver<'_, T> { #[derive(Clone, Debug, PartialEq, Eq, Hash)] struct SpeculativeItemRender<'a, T: EntryLike> { rendered: ElemChildren, + rendered_without_ibid: ElemChildren, entry: &'a T, cite_props: CiteProperties<'a>, checked_disambiguate: bool, @@ -177,6 +178,17 @@ impl<'a, T: EntryLike + Hash + PartialEq + Eq + Debug> BibliographyDriver<'a, T> None, ); + let mut cite_props_without_ibid = cite_props.clone(); + cite_props_without_ibid.speculative.ibid = IbidState::Different; + let ctx_without_ibid = style.do_citation( + *entry, + cite_props_without_ibid, + item.locale.as_ref(), + citation.locale.as_ref(), + item.purpose, + None, + ); + // Copy the identifier usage from the context. Assume it does // not change throughout disambiguation. cite_props.speculative.identifier_usage = @@ -191,6 +203,7 @@ impl<'a, T: EntryLike + Hash + PartialEq + Eq + Debug> BibliographyDriver<'a, T> group_idx: None, locator: item.locator, rendered: ctx.flush(), + rendered_without_ibid: ctx_without_ibid.flush(), hidden: item.hidden, locale: item.locale.clone(), purpose: item.purpose, @@ -811,7 +824,7 @@ fn find_ambiguous_sets( continue; } - let buf = format!("{:?}", item.rendered); + let buf = format!("{:?}", item.rendered_without_ibid); match map.entry(buf) { HmEntry::Occupied(entry) => match *entry.get() { PotentialDisambiguation::Single(pos) => {