mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
css, dom, text: Stop copying so much. Also stop asserting.
This commit is contained in:
parent
230ac2dd17
commit
61f558dffc
3 changed files with 33 additions and 7 deletions
|
@ -583,8 +583,14 @@ impl GlyphStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn iter_glyphs_for_range(&self, range: &const Range, cb: fn&(uint, GlyphInfo/&) -> bool) {
|
fn iter_glyphs_for_range(&self, range: &const Range, cb: fn&(uint, GlyphInfo/&) -> bool) {
|
||||||
assert range.begin() < self.entry_buffer.len();
|
if range.begin() >= self.entry_buffer.len() {
|
||||||
assert range.end() <= self.entry_buffer.len();
|
error!("iter_glyphs_for_range: range.begin beyond length!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if range.end() > self.entry_buffer.len() {
|
||||||
|
error!("iter_glyphs_for_range: range.end beyond length!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for range.eachi |i| {
|
for range.eachi |i| {
|
||||||
if !self.iter_glyphs_for_index(i, cb) { break; }
|
if !self.iter_glyphs_for_index(i, cb) { break; }
|
||||||
|
@ -609,8 +615,12 @@ impl GlyphStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn char_is_newline(i: uint) -> bool {
|
fn char_is_newline(i: uint) -> bool {
|
||||||
assert i < self.entry_buffer.len();
|
if i >= self.entry_buffer.len() {
|
||||||
self.entry_buffer[i].char_is_newline()
|
error!("char_is_newline: beyond entry buffer!");
|
||||||
|
false
|
||||||
|
} else {
|
||||||
|
self.entry_buffer[i].char_is_newline()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_ligature_start(i: uint) -> bool {
|
fn is_ligature_start(i: uint) -> bool {
|
||||||
|
|
|
@ -84,9 +84,11 @@ impl NodeSelectHandler: SelectHandler<Node> {
|
||||||
do node.read |data| {
|
do node.read |data| {
|
||||||
match *data.kind {
|
match *data.kind {
|
||||||
Element(ref data) => {
|
Element(ref data) => {
|
||||||
match data.get_attr("id") {
|
do data.with_attr("id") |existing_id_opt| {
|
||||||
None => false,
|
match existing_id_opt {
|
||||||
Some(existing_id) => str::eq_slice(id, existing_id)
|
None => false,
|
||||||
|
Some(existing_id) => str::eq_slice(id, existing_id)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => fail ~"attempting to style non-element node"
|
_ => fail ~"attempting to style non-element node"
|
||||||
|
|
|
@ -20,6 +20,20 @@ impl ElementData {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Gets an attribute without copying.
|
||||||
|
//
|
||||||
|
// FIXME: Should not take a closure, but we need covariant type parameters for
|
||||||
|
// that.
|
||||||
|
fn with_attr<R>(name: &str, f: &fn(Option<&str>) -> R) -> R {
|
||||||
|
for self.attrs.each |attr| {
|
||||||
|
if name == attr.name {
|
||||||
|
let value: &str = attr.value;
|
||||||
|
return f(Some(value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
f(None)
|
||||||
|
}
|
||||||
|
|
||||||
fn set_attr(name: &str, value: ~str) {
|
fn set_attr(name: &str, value: ~str) {
|
||||||
let idx = do self.attrs.position |attr| { name == attr.name };
|
let idx = do self.attrs.position |attr| { name == attr.name };
|
||||||
match idx {
|
match idx {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue