mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
Remove some insidious implicit copying in the TextRunScanner.
This commit is contained in:
parent
26d5cfb509
commit
d979b9fbc6
1 changed files with 36 additions and 40 deletions
|
@ -63,46 +63,42 @@ impl TextRunScanner {
|
||||||
fn scan_for_runs(ctx: &LayoutContext) {
|
fn scan_for_runs(ctx: &LayoutContext) {
|
||||||
// if reused, must be reset.
|
// if reused, must be reset.
|
||||||
assert !self.in_clump;
|
assert !self.in_clump;
|
||||||
let in_boxes = self.flow.inline().boxes;
|
assert self.flow.inline().boxes.len() > 0;
|
||||||
assert in_boxes.len() > 0;
|
|
||||||
|
|
||||||
debug!("scanning %u boxes for text runs...", in_boxes.len());
|
do self.flow.inline().boxes.swap |in_boxes| {
|
||||||
|
debug!("scanning %u boxes for text runs...", in_boxes.len());
|
||||||
|
|
||||||
|
let temp_boxes = DVec();
|
||||||
|
let mut prev_box: @RenderBox = in_boxes[0];
|
||||||
|
|
||||||
let temp_boxes = DVec();
|
for uint::range(0, in_boxes.len()) |i| {
|
||||||
let mut prev_box: @RenderBox = in_boxes[0];
|
debug!("considering box: %?", in_boxes[i].debug_str());
|
||||||
|
|
||||||
for uint::range(0, in_boxes.len()) |i| {
|
let can_coalesce_with_prev = i > 0 && boxes_can_be_coalesced(prev_box, in_boxes[i]);
|
||||||
debug!("considering box: %?", in_boxes[i].debug_str());
|
|
||||||
|
|
||||||
let can_coalesce_with_prev = i > 0 && boxes_can_be_coalesced(prev_box, in_boxes[i]);
|
match (self.in_clump, can_coalesce_with_prev) {
|
||||||
|
// start a new clump
|
||||||
|
(false, _) => { self.reset_clump_to_index(i); },
|
||||||
|
// extend clump
|
||||||
|
(true, true) => { self.clump_end = i; },
|
||||||
|
// boundary detected; flush and start new clump
|
||||||
|
(true, false) => {
|
||||||
|
self.flush_clump_to_list(ctx, in_boxes, &temp_boxes);
|
||||||
|
self.reset_clump_to_index(i);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
prev_box = in_boxes[i];
|
||||||
|
}
|
||||||
|
// handle remaining clumps
|
||||||
|
if self.in_clump {
|
||||||
|
self.flush_clump_to_list(ctx, in_boxes, &temp_boxes);
|
||||||
|
}
|
||||||
|
|
||||||
match (self.in_clump, can_coalesce_with_prev) {
|
debug!("swapping out boxes.");
|
||||||
// start a new clump
|
// swap out old and new box list of flow, by supplying
|
||||||
(false, _) => { self.reset_clump_to_index(i); },
|
// temp boxes as return value to boxes.swap |...|
|
||||||
// extend clump
|
dvec::unwrap(temp_boxes)
|
||||||
(true, true) => { self.clump_end = i; },
|
|
||||||
// boundary detected; flush and start new clump
|
|
||||||
(true, false) => {
|
|
||||||
self.flush_clump_to_list(ctx, &temp_boxes);
|
|
||||||
self.reset_clump_to_index(i);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
prev_box = in_boxes[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
// handle remaining clumps
|
|
||||||
if self.in_clump {
|
|
||||||
self.flush_clump_to_list(ctx, &temp_boxes);
|
|
||||||
}
|
|
||||||
|
|
||||||
debug!("swapping out boxes.");
|
|
||||||
// swap out old and new box list of flow
|
|
||||||
self.flow.inline().boxes.set(dvec::unwrap(temp_boxes));
|
|
||||||
|
|
||||||
debug!("new inline flow boxes:");
|
|
||||||
do self.flow.inline().boxes.each |box| {
|
|
||||||
debug!("%s", box.debug_str()); true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper functions
|
// helper functions
|
||||||
|
@ -125,12 +121,12 @@ impl TextRunScanner {
|
||||||
self.in_clump = true;
|
self.in_clump = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn flush_clump_to_list(ctx: &LayoutContext, temp_boxes: &DVec<@RenderBox>) {
|
fn flush_clump_to_list(ctx: &LayoutContext,
|
||||||
|
in_boxes: &[@RenderBox], temp_boxes: &DVec<@RenderBox>) {
|
||||||
assert self.in_clump;
|
assert self.in_clump;
|
||||||
|
|
||||||
debug!("flushing when start=%?,end=%?", self.clump_start, self.clump_end);
|
debug!("flushing when start=%?,end=%?", self.clump_start, self.clump_end);
|
||||||
|
|
||||||
let in_boxes = self.flow.inline().boxes;
|
|
||||||
let is_singleton = (self.clump_start == self.clump_end);
|
let is_singleton = (self.clump_start == self.clump_end);
|
||||||
let is_text_clump = match in_boxes[self.clump_start] {
|
let is_text_clump = match in_boxes[self.clump_start] {
|
||||||
@UnscannedTextBox(*) => true,
|
@UnscannedTextBox(*) => true,
|
||||||
|
@ -154,11 +150,11 @@ impl TextRunScanner {
|
||||||
let mut run_str : ~str = ~"";
|
let mut run_str : ~str = ~"";
|
||||||
// TODO: is using ropes to construct the merged text any faster?
|
// TODO: is using ropes to construct the merged text any faster?
|
||||||
do uint::range(self.clump_start, self.clump_end+1) |i| {
|
do uint::range(self.clump_start, self.clump_end+1) |i| {
|
||||||
run_str = str::append(run_str, in_boxes[i].raw_text()); true
|
run_str = str::append(copy run_str, in_boxes[i].raw_text()); true
|
||||||
}
|
}
|
||||||
// TODO: use actual font for corresponding DOM node to create text run.
|
// TODO: use actual font for corresponding DOM node to create text run.
|
||||||
let run = TextRun(&*ctx.font_cache.get_test_font(), move run_str);
|
let run = @TextRun(&*ctx.font_cache.get_test_font(), move run_str);
|
||||||
let box_guts = TextBoxData(@run, 0, run.text.len());
|
let box_guts = TextBoxData(run, 0, run.text.len());
|
||||||
debug!("pushing when start=%?,end=%?", self.clump_start, self.clump_end);
|
debug!("pushing when start=%?,end=%?", self.clump_start, self.clump_end);
|
||||||
temp_boxes.push(@TextBox(copy *in_boxes[self.clump_start].d(), box_guts));
|
temp_boxes.push(@TextBox(copy *in_boxes[self.clump_start].d(), box_guts));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue