mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Use Option functions to make logic clearer
This commit is contained in:
parent
a351710004
commit
61216c301d
1 changed files with 24 additions and 36 deletions
|
@ -355,14 +355,12 @@ 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,
|
||||||
|
@ -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,
|
||||||
|
@ -743,21 +734,18 @@ impl<'a> Iterator<(CharIndex, GlyphInfo<'a>)> for GlyphIterator<'a> {
|
||||||
if self.glyph_range.is_some() {
|
if self.glyph_range.is_some() {
|
||||||
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());
|
if entry.is_simple() {
|
||||||
if entry.is_simple() {
|
Some((self.char_index, SimpleGlyphInfo(self.store, i)))
|
||||||
Some((self.char_index, SimpleGlyphInfo(self.store, i)))
|
} else {
|
||||||
} else {
|
// 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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue