From 4e3e5a879d4ff03ae09efb2f9ffe44ca823ed2ae Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sat, 15 Sep 2012 16:31:38 -0700 Subject: [PATCH] Do a little less copying in TextRun.split --- src/rust-mozjs | 2 +- src/servo/text/text_run.rs | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/rust-mozjs b/src/rust-mozjs index e2b17f323b0..de66662c301 160000 --- a/src/rust-mozjs +++ b/src/rust-mozjs @@ -1 +1 @@ -Subproject commit e2b17f323b0ab2d6a2d806d114bd1e61f3b1ba50 +Subproject commit de66662c301b2c00dacabdf0d82adf22d16232b4 diff --git a/src/servo/text/text_run.rs b/src/servo/text/text_run.rs index 5333501fa7a..16c4e6a4e27 100644 --- a/src/servo/text/text_run.rs +++ b/src/servo/text/text_run.rs @@ -30,18 +30,18 @@ impl TextRun { let mut curr_run = ~""; for iter_indivisible_slices(font, self.text) |slice| { - let mut candidate = curr_run; + let mut candidate = copy curr_run; if candidate.is_not_empty() { - candidate += " "; // FIXME: just inserting spaces between words can't be right + str::push_str(candidate, " "); // FIXME: just inserting spaces between words can't be right } - candidate += slice; + str::push_str(candidate, slice); let glyphs = shape_text(font, candidate); let size = glyph_run_size(glyphs); if size.width <= h_offset { - curr_run = candidate; + curr_run = move candidate; } else { break; } @@ -50,8 +50,14 @@ impl TextRun { assert curr_run.is_not_empty(); let first = move curr_run; - let second = str::slice(self.text, first.len(), self.text.len()); - let second = second.trim_left(); + let second_start = match str::find_from(self.text, first.len(), |c| !char::is_whitespace(c)) { + Some(idx) => idx, + None => { + // This will be an empty string + self.text.len() + } + }; + let second = str::slice(self.text, second_start, self.text.len()); return (TextRun(font, first), TextRun(font, second)); } }