rust: CachedMathEngine renders through its MathRenderer impl only

The inherent render and the trait impl were two copies of one method, the
trait one delegating to the other; the body now lives in the trait impl
(audit Math-1). gui-app already imports MathRenderer where it calls it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Greg ShuflinandClaude Opus 5.5 committed 2026-09-28 13:31:29 -07:00
1 parent e80707e6bb
commit 2939004852
1 file changed
+11 -21
+11 -21
View File
@@ -51,26 +51,6 @@ impl<E: MathEngine> CachedMathEngine<E> {
pub fn new(engine: E, capacity: NonZeroUsize) -> Self {
Self { engine, cache: Mutex::new(LruCache::new(capacity)) }
}
/// Render `src`, serving a cached bitmap when one exists for exactly
/// these inputs. Returns an `Arc` so repeated hits — every keystroke, for
/// every *other* formula in the note — clone a pointer rather than a
/// multi-KB bitmap.
pub fn render(
&self,
src: &str,
display: bool,
font_size_px: f32,
dpr: f32,
) -> Result<Arc<MathRender>, MathError> {
let key = MathCacheKey::new(src, display, font_size_px, dpr);
let mut cache = self.cache.lock().unwrap_or_else(|e| e.into_inner());
cache
.try_get_or_insert(key, || {
self.engine.render(src, display, font_size_px, dpr).map(Arc::new)
})
.cloned()
}
}
/// Object-safe view of [`CachedMathEngine`], for callers that pick an engine
@@ -88,6 +68,10 @@ pub trait MathRenderer: Send + Sync {
}
impl<E: MathEngine + Send + Sync> MathRenderer for CachedMathEngine<E> {
/// Render `src`, serving a cached bitmap when one exists for exactly
/// these inputs. Returns an `Arc` so repeated hits — every keystroke, for
/// every *other* formula in the note — clone a pointer rather than a
/// multi-KB bitmap.
fn render(
&self,
src: &str,
@@ -95,7 +79,13 @@ impl<E: MathEngine + Send + Sync> MathRenderer for CachedMathEngine<E> {
font_size_px: f32,
dpr: f32,
) -> Result<Arc<MathRender>, MathError> {
CachedMathEngine::render(self, src, display, font_size_px, dpr)
let key = MathCacheKey::new(src, display, font_size_px, dpr);
let mut cache = self.cache.lock().unwrap_or_else(|e| e.into_inner());
cache
.try_get_or_insert(key, || {
self.engine.render(src, display, font_size_px, dpr).map(Arc::new)
})
.cloned()
}
}