Use Option functions to make logic clearer

This commit is contained in:
Brendan Zabarauskas 2014-06-20 09:07:42 -07:00
parent a351710004
commit 61216c301d

View file

@ -355,15 +355,13 @@ impl<'a> DetailedGlyphStore {
detail_offset: 0, // unused detail_offset: 0, // unused
}; };
match self.detail_lookup.as_slice().binary_search_index(&key) { let i = self.detail_lookup.as_slice().binary_search_index(&key)
None => fail!("Invalid index not found in detailed glyph lookup table!"), .expect("Invalid index not found in detailed glyph lookup table!");
Some(i) => {
assert!(i + (count as uint) <= self.detail_buffer.len()); assert!(i + (count as uint) <= self.detail_buffer.len());
// return a slice into the buffer // return a slice into the buffer
self.detail_buffer.slice(i, i + count as uint) self.detail_buffer.slice(i, i + count as uint)
} }
}
}
fn get_detailed_glyph_with_index(&'a self, fn get_detailed_glyph_with_index(&'a self,
entry_offset: CharIndex, entry_offset: CharIndex,
@ -377,13 +375,11 @@ impl<'a> DetailedGlyphStore {
detail_offset: 0, // unused detail_offset: 0, // unused
}; };
match self.detail_lookup.as_slice().binary_search_index(&key) { let i = self.detail_lookup.as_slice().binary_search_index(&key)
None => fail!("Invalid index not found in detailed glyph lookup table!"), .expect("Invalid index not found in detailed glyph lookup table!");
Some(i) => {
assert!(i + (detail_offset as uint) < self.detail_buffer.len()); assert!(i + (detail_offset as uint) < self.detail_buffer.len());
self.detail_buffer.get(i+(detail_offset as uint)) self.detail_buffer.get(i + (detail_offset as uint))
}
}
} }
fn ensure_sorted(&mut self) { fn ensure_sorted(&mut self) {
@ -432,15 +428,10 @@ impl GlyphData {
cluster_start: bool, cluster_start: bool,
ligature_start: bool) ligature_start: bool)
-> GlyphData { -> GlyphData {
let offset = match offset {
None => Zero::zero(),
Some(o) => o,
};
GlyphData { GlyphData {
id: id, id: id,
advance: advance, advance: advance,
offset: offset, offset: offset.unwrap_or(Zero::zero()),
is_missing: is_missing, is_missing: is_missing,
cluster_start: cluster_start, cluster_start: cluster_start,
ligature_start: ligature_start, ligature_start: ligature_start,
@ -744,8 +735,7 @@ impl<'a> Iterator<(CharIndex, GlyphInfo<'a>)> for GlyphIterator<'a> {
self.next_glyph_range() self.next_glyph_range()
} else { } else {
// No glyph range. Look at next character. // No glyph range. Look at next character.
match self.char_range.next() { self.char_range.next().and_then(|i| {
Some(i) => {
self.char_index = i; self.char_index = i;
assert!(i < self.store.char_len()); assert!(i < self.store.char_len());
let entry = self.store.entry_buffer.get(i.to_uint()); let entry = self.store.entry_buffer.get(i.to_uint());
@ -755,9 +745,7 @@ impl<'a> Iterator<(CharIndex, GlyphInfo<'a>)> for GlyphIterator<'a> {
// Fall back to the slow path. // Fall back to the slow path.
self.next_complex_glyph(entry, i) self.next_complex_glyph(entry, i)
} }
}, })
None => None
}
} }
} }
} }