Skip to content
Permalink
Browse files

Use Option functions to make logic clearer

  • Loading branch information
brendanzab committed Jun 20, 2014
1 parent a351710 commit 61216c301deadc95b4156f8ddf5348e6e410a5d4
Showing with 24 additions and 36 deletions.
  1. +24 −36 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)
}
})
}
}
}

0 comments on commit 61216c3

Please sign in to comment.
You can’t perform that action at this time.