From 61216c301deadc95b4156f8ddf5348e6e410a5d4 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Fri, 20 Jun 2014 09:07:42 -0700 Subject: [PATCH] Use Option functions to make logic clearer --- src/components/gfx/text/glyph.rs | 60 +++++++++++++------------------- 1 file changed, 24 insertions(+), 36 deletions(-) diff --git a/src/components/gfx/text/glyph.rs b/src/components/gfx/text/glyph.rs index 17ef3b5acd0..67091548fac 100644 --- a/src/components/gfx/text/glyph.rs +++ b/src/components/gfx/text/glyph.rs @@ -355,14 +355,12 @@ impl<'a> DetailedGlyphStore { detail_offset: 0, // unused }; - match self.detail_lookup.as_slice().binary_search_index(&key) { - None => fail!("Invalid index not found in detailed glyph lookup table!"), - Some(i) => { - assert!(i + (count as uint) <= self.detail_buffer.len()); - // return a slice into the buffer - self.detail_buffer.slice(i, i + count as uint) - } - } + let i = self.detail_lookup.as_slice().binary_search_index(&key) + .expect("Invalid index not found in detailed glyph lookup table!"); + + assert!(i + (count as uint) <= self.detail_buffer.len()); + // return a slice into the buffer + self.detail_buffer.slice(i, i + count as uint) } fn get_detailed_glyph_with_index(&'a self, @@ -377,13 +375,11 @@ impl<'a> DetailedGlyphStore { detail_offset: 0, // unused }; - match self.detail_lookup.as_slice().binary_search_index(&key) { - None => fail!("Invalid index not found in detailed glyph lookup table!"), - Some(i) => { - assert!(i + (detail_offset as uint) < self.detail_buffer.len()); - self.detail_buffer.get(i+(detail_offset as uint)) - } - } + let i = self.detail_lookup.as_slice().binary_search_index(&key) + .expect("Invalid index not found in detailed glyph lookup table!"); + + assert!(i + (detail_offset as uint) < self.detail_buffer.len()); + self.detail_buffer.get(i + (detail_offset as uint)) } fn ensure_sorted(&mut self) { @@ -432,15 +428,10 @@ impl GlyphData { cluster_start: bool, ligature_start: bool) -> GlyphData { - let offset = match offset { - None => Zero::zero(), - Some(o) => o, - }; - GlyphData { id: id, advance: advance, - offset: offset, + offset: offset.unwrap_or(Zero::zero()), is_missing: is_missing, cluster_start: cluster_start, ligature_start: ligature_start, @@ -743,21 +734,18 @@ impl<'a> Iterator<(CharIndex, GlyphInfo<'a>)> for GlyphIterator<'a> { if self.glyph_range.is_some() { self.next_glyph_range() } else { - // No glyph range. Look at next character. - match self.char_range.next() { - Some(i) => { - self.char_index = i; - assert!(i < self.store.char_len()); - let entry = self.store.entry_buffer.get(i.to_uint()); - if entry.is_simple() { - Some((self.char_index, SimpleGlyphInfo(self.store, i))) - } else { - // Fall back to the slow path. - self.next_complex_glyph(entry, i) - } - }, - None => None - } + // No glyph range. Look at next character. + self.char_range.next().and_then(|i| { + self.char_index = i; + assert!(i < self.store.char_len()); + let entry = self.store.entry_buffer.get(i.to_uint()); + if entry.is_simple() { + Some((self.char_index, SimpleGlyphInfo(self.store, i))) + } else { + // Fall back to the slow path. + self.next_complex_glyph(entry, i) + } + }) } } }