Skip to content

Commit b351119

Browse files
committed
Simplify glyph effect processing (this assumes strictly increasing order of starts)
1 parent cc5fef4 commit b351119

File tree

1 file changed

+9
-19
lines changed

1 file changed

+9
-19
lines changed

src/display/glyph_pos.rs

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -236,31 +236,20 @@ impl<'a, E: Copy + Default> GlyphRun<'a, E> {
236236

237237
if ltr {
238238
// Find the next active effect
239-
loop {
240-
effect_cur = effect_next;
241-
effect_next += 1;
242-
if self
243-
.effects
244-
.get(effect_next)
245-
.map(|e| e.0 > glyph.index)
246-
.unwrap_or(true)
247-
{
248-
break;
249-
}
250-
}
239+
effect_cur = effect_next;
240+
effect_next += 1;
251241
next_start = self
252242
.effects
253243
.get(effect_next)
254244
.map(|e| e.0)
245+
.inspect(|start| debug_assert!(*start > glyph.index))
255246
.unwrap_or(u32::MAX);
256247
} else {
257248
// Find the previous active effect
258-
loop {
259-
effect_cur = effect_cur.wrapping_sub(1);
260-
if self.effects.get(effect_cur).map(|e| e.0).unwrap_or(0) <= glyph.index {
261-
break;
262-
}
263-
}
249+
effect_cur = effect_cur.wrapping_sub(1);
250+
debug_assert!(
251+
self.effects.get(effect_cur).map(|e| e.0).unwrap_or(0) <= glyph.index
252+
);
264253
}
265254
fmt = self
266255
.effects
@@ -395,7 +384,8 @@ impl TextDisplay {
395384
/// The `effects` sequence may be used for rendering effects: glyph color,
396385
/// background color, strike-through, underline. Use `&[]` for no effects
397386
/// (effectively using the default value of `E` everywhere), or use a
398-
/// sequence such that `effects[i].0` values are strictly increasing. A
387+
/// sequence such that `effects[i].0` values are strictly increasing and
388+
/// each mapping to a distinct glyph cluster. A
399389
/// glyph for index `j` in the source text will use effect `effects[i].1`
400390
/// where `i` is the largest value such that `effects[i].0 <= j`, or the
401391
/// default value of `E` if no such `i` exists.

0 commit comments

Comments
 (0)