From 9e765ceba6161f66b7af1127fae3d910525ce654 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Tue, 29 Oct 2019 13:49:07 -0700 Subject: [PATCH] highlight: Skip injection codepath if there are no ranges found --- highlight/src/lib.rs | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/highlight/src/lib.rs b/highlight/src/lib.rs index 3e3b7fa9..3431d7b7 100644 --- a/highlight/src/lib.rs +++ b/highlight/src/lib.rs @@ -712,17 +712,20 @@ where // to the highlighted document. if let Some(config) = language.and_then(&self.injection_callback) { if !content_nodes.is_empty() { - match HighlightIterLayer::new( - config, - self.source, - self.context, - self.cancellation_flag, - self.layers[0].depth + 1, - self.layers[0] - .intersect_ranges(&content_nodes, include_children), - ) { - Ok(layer) => self.insert_layer(layer), - Err(e) => return Some(Err(e)), + let ranges = self.layers[0] + .intersect_ranges(&content_nodes, include_children); + if !ranges.is_empty() { + match HighlightIterLayer::new( + config, + self.source, + self.context, + self.cancellation_flag, + self.layers[0].depth + 1, + ranges, + ) { + Ok(layer) => self.insert_layer(layer), + Err(e) => return Some(Err(e)), + } } } }