Remove old borrow check workarounds and appease the new borrow checker.

This commit is contained in:
Jack Moffitt 2013-05-10 14:54:15 -06:00
parent 4d0c20246a
commit 7234635aa5
5 changed files with 55 additions and 68 deletions

View file

@ -186,7 +186,7 @@ pub impl Content {
} }
fn handle_msg(&mut self) -> bool { fn handle_msg(&mut self) -> bool {
match select2i(&self.control_port, &self.event_port) { match select2i(&mut self.control_port, &mut self.event_port) {
either::Left(*) => { either::Left(*) => {
let msg = self.control_port.recv(); let msg = self.control_port.recv();
self.handle_control_msg(msg) self.handle_control_msg(msg)

View file

@ -168,15 +168,12 @@ pub impl RenderBox {
match *self { match *self {
GenericRenderBoxClass(generic_box) => callback(generic_box), GenericRenderBoxClass(generic_box) => callback(generic_box),
ImageRenderBoxClass(image_box) => { ImageRenderBoxClass(image_box) => {
let image_box = &*image_box; // FIXME: Borrow check workaround.
callback(&image_box.base) callback(&image_box.base)
} }
TextRenderBoxClass(text_box) => { TextRenderBoxClass(text_box) => {
let text_box = &*text_box; // FIXME: Borrow check workaround.
callback(&text_box.base) callback(&text_box.base)
} }
UnscannedTextRenderBoxClass(unscanned_text_box) => { UnscannedTextRenderBoxClass(unscanned_text_box) => {
let unscanned_text_box = &*unscanned_text_box; // FIXME: Borrow check workaround.
callback(&unscanned_text_box.base) callback(&unscanned_text_box.base)
} }
} }
@ -188,16 +185,12 @@ pub impl RenderBox {
match *self { match *self {
GenericRenderBoxClass(generic_box) => callback(generic_box), GenericRenderBoxClass(generic_box) => callback(generic_box),
ImageRenderBoxClass(image_box) => { ImageRenderBoxClass(image_box) => {
let image_box = &mut *image_box; // FIXME: Borrow check workaround.
callback(&mut image_box.base) callback(&mut image_box.base)
} }
TextRenderBoxClass(text_box) => { TextRenderBoxClass(text_box) => {
let text_box = &mut *text_box; // FIXME: Borrow check workaround.
callback(&mut text_box.base) callback(&mut text_box.base)
} }
UnscannedTextRenderBoxClass(unscanned_text_box) => { UnscannedTextRenderBoxClass(unscanned_text_box) => {
// FIXME: Borrow check workaround.
let unscanned_text_box = &mut *unscanned_text_box;
callback(&mut unscanned_text_box.base) callback(&mut unscanned_text_box.base)
} }
} }
@ -238,7 +231,6 @@ pub impl RenderBox {
fn is_whitespace_only(&self) -> bool { fn is_whitespace_only(&self) -> bool {
match *self { match *self {
UnscannedTextRenderBoxClass(unscanned_text_box) => { UnscannedTextRenderBoxClass(unscanned_text_box) => {
let mut unscanned_text_box = &mut *unscanned_text_box; // FIXME: Borrow check.
unscanned_text_box.text.is_whitespace() unscanned_text_box.text.is_whitespace()
} }
_ => false _ => false
@ -269,8 +261,6 @@ pub impl RenderBox {
} }
TextRenderBoxClass(text_box) => { TextRenderBoxClass(text_box) => {
let text_box = &mut *text_box; // FIXME: Borrow check.
let mut pieces_processed_count: uint = 0; let mut pieces_processed_count: uint = 0;
let mut remaining_width: Au = max_width; let mut remaining_width: Au = max_width;
let mut left_range = Range::new(text_box.text_data.range.begin(), 0); let mut left_range = Range::new(text_box.text_data.range.begin(), 0);
@ -379,7 +369,6 @@ pub impl RenderBox {
} }
TextRenderBoxClass(text_box) => { TextRenderBoxClass(text_box) => {
let mut text_box = &mut *text_box; // FIXME: Borrow check.
text_box.text_data.run.min_width_for_range(&text_box.text_data.range) text_box.text_data.run.min_width_for_range(&text_box.text_data.range)
} }
@ -401,8 +390,6 @@ pub impl RenderBox {
} }
TextRenderBoxClass(text_box) => { TextRenderBoxClass(text_box) => {
let mut text_box = &mut *text_box; // FIXME: Borrow check bug.
// A text box cannot span lines, so assume that this is an unsplit text box. // A text box cannot span lines, so assume that this is an unsplit text box.
// //
// TODO: If text boxes have been split to wrap lines, then they could report a // TODO: If text boxes have been split to wrap lines, then they could report a
@ -567,8 +554,6 @@ pub impl RenderBox {
match *self { match *self {
UnscannedTextRenderBoxClass(*) => fail!(~"Shouldn't see unscanned boxes here."), UnscannedTextRenderBoxClass(*) => fail!(~"Shouldn't see unscanned boxes here."),
TextRenderBoxClass(text_box) => { TextRenderBoxClass(text_box) => {
let text_box = &mut *text_box; // FIXME: Borrow check bug.
let nearest_ancestor_element = self.nearest_ancestor_element(); let nearest_ancestor_element = self.nearest_ancestor_element();
let color = nearest_ancestor_element.style().color().to_gfx_color(); let color = nearest_ancestor_element.style().color().to_gfx_color();
@ -783,13 +768,11 @@ impl DebugMethods for RenderBox {
GenericRenderBoxClass(*) => ~"GenericRenderBox", GenericRenderBoxClass(*) => ~"GenericRenderBox",
ImageRenderBoxClass(*) => ~"ImageRenderBox", ImageRenderBoxClass(*) => ~"ImageRenderBox",
TextRenderBoxClass(text_box) => { TextRenderBoxClass(text_box) => {
let mut text_box = &mut *text_box; // FIXME: Borrow check bug.
fmt!("TextRenderBox(text=%s)", str::substr(text_box.text_data.run.text, fmt!("TextRenderBox(text=%s)", str::substr(text_box.text_data.run.text,
text_box.text_data.range.begin(), text_box.text_data.range.begin(),
text_box.text_data.range.length())) text_box.text_data.range.length()))
} }
UnscannedTextRenderBoxClass(text_box) => { UnscannedTextRenderBoxClass(text_box) => {
let mut text_box = &mut *text_box; // FIXME: Borrow check bug.
fmt!("UnscannedTextRenderBox(%s)", text_box.text) fmt!("UnscannedTextRenderBox(%s)", text_box.text)
} }
}; };

View file

@ -125,7 +125,6 @@ impl BoxGenerator {
// depending on flow, make a box for this node. // depending on flow, make a box for this node.
match self.flow { match self.flow {
InlineFlow(inline) => { InlineFlow(inline) => {
let mut inline = &mut *inline;
let node_range_start = inline.boxes.len(); let node_range_start = inline.boxes.len();
self.range_stack.push(node_range_start); self.range_stack.push(node_range_start);
@ -387,24 +386,38 @@ pub impl LayoutTreeBuilder {
// check first/last child for whitespace-ness // check first/last child for whitespace-ness
for first_child.each |first_flow| { for first_child.each |first_flow| {
if first_flow.starts_inline_flow() { if first_flow.starts_inline_flow() {
let boxes = &mut first_flow.inline().boxes; // FIXME: workaround for rust#6393
let mut do_remove = false;
{
let boxes = &first_flow.inline().boxes;
if boxes.len() == 1 && boxes[0].is_whitespace_only() { if boxes.len() == 1 && boxes[0].is_whitespace_only() {
debug!("LayoutTreeBuilder: pruning whitespace-only first child flow \ debug!("LayoutTreeBuilder: pruning whitespace-only first child flow \
f%d from parent f%d", f%d from parent f%d",
first_flow.id(), first_flow.id(),
parent_flow.id()); parent_flow.id());
do_remove = true;
}
}
if (do_remove) {
parent_flow.remove_child(*first_flow); parent_flow.remove_child(*first_flow);
} }
} }
} }
for last_child.each |last_flow| { for last_child.each |last_flow| {
if last_flow.starts_inline_flow() { if last_flow.starts_inline_flow() {
let boxes = &mut last_flow.inline().boxes; // FIXME: workaround for rust#6393
let mut do_remove = false;
{
let boxes = &last_flow.inline().boxes;
if boxes.len() == 1 && boxes.last().is_whitespace_only() { if boxes.len() == 1 && boxes.last().is_whitespace_only() {
debug!("LayoutTreeBuilder: pruning whitespace-only last child flow \ debug!("LayoutTreeBuilder: pruning whitespace-only last child flow \
f%d from parent f%d", f%d from parent f%d",
last_flow.id(), last_flow.id(),
parent_flow.id()); parent_flow.id());
do_remove = true;
}
}
if (do_remove) {
parent_flow.remove_child(*last_flow); parent_flow.remove_child(*last_flow);
} }
} }

View file

@ -76,17 +76,14 @@ impl TreeNodeRef<FlowData> for FlowContext {
match *self { match *self {
AbsoluteFlow(info) => callback(info), AbsoluteFlow(info) => callback(info),
BlockFlow(info) => { BlockFlow(info) => {
let info = &*info; // FIXME: Borrow check workaround.
callback(&info.common) callback(&info.common)
} }
FloatFlow(info) => callback(info), FloatFlow(info) => callback(info),
InlineBlockFlow(info) => callback(info), InlineBlockFlow(info) => callback(info),
InlineFlow(info) => { InlineFlow(info) => {
let info = &*info; // FIXME: Borrow check workaround.
callback(&info.common) callback(&info.common)
} }
RootFlow(info) => { RootFlow(info) => {
let info = &*info; // FIXME: Borrow check workaround.
callback(&info.common) callback(&info.common)
} }
TableFlow(info) => callback(info), TableFlow(info) => callback(info),
@ -96,17 +93,14 @@ impl TreeNodeRef<FlowData> for FlowContext {
match *self { match *self {
AbsoluteFlow(info) => callback(info), AbsoluteFlow(info) => callback(info),
BlockFlow(info) => { BlockFlow(info) => {
let info = &mut *info; // FIXME: Borrow check workaround.
callback(&mut info.common) callback(&mut info.common)
} }
FloatFlow(info) => callback(info), FloatFlow(info) => callback(info),
InlineBlockFlow(info) => callback(info), InlineBlockFlow(info) => callback(info),
InlineFlow(info) => { InlineFlow(info) => {
let info = &mut *info; // FIXME: Borrow check workaround.
callback(&mut info.common) callback(&mut info.common)
} }
RootFlow(info) => { RootFlow(info) => {
let info = &mut *info; // FIXME: Borrow check workaround.
callback(&mut info.common) callback(&mut info.common)
} }
TableFlow(info) => callback(info), TableFlow(info) => callback(info),
@ -388,7 +382,6 @@ impl DebugMethods for FlowContext {
fn debug_str(&self) -> ~str { fn debug_str(&self) -> ~str {
let repr = match *self { let repr = match *self {
InlineFlow(inline) => { InlineFlow(inline) => {
let inline = &mut *inline;
let mut s = inline.boxes.foldl(~"InlineFlow(children=", |s, box| { let mut s = inline.boxes.foldl(~"InlineFlow(children=", |s, box| {
fmt!("%s b%d", *s, box.id()) fmt!("%s b%d", *s, box.id())
}); });
@ -396,14 +389,12 @@ impl DebugMethods for FlowContext {
s s
}, },
BlockFlow(block) => { BlockFlow(block) => {
let block = &mut *block;
match block.box { match block.box {
Some(box) => fmt!("BlockFlow(box=b%d)", box.id()), Some(box) => fmt!("BlockFlow(box=b%d)", box.id()),
None => ~"BlockFlow", None => ~"BlockFlow",
} }
}, },
RootFlow(root) => { RootFlow(root) => {
let root = &mut *root;
match root.box { match root.box {
Some(box) => fmt!("RootFlow(box=b%d)", box.id()), Some(box) => fmt!("RootFlow(box=b%d)", box.id()),
None => ~"RootFlow", None => ~"RootFlow",

View file

@ -173,7 +173,7 @@ impl TextRunScanner {
impl TextRunScanner { impl TextRunScanner {
fn scan_for_runs(&mut self, ctx: &mut LayoutContext, flow: FlowContext) { fn scan_for_runs(&mut self, ctx: &mut LayoutContext, flow: FlowContext) {
let inline = &mut *flow.inline(); let inline = flow.inline();
assert!(inline.boxes.len() > 0); assert!(inline.boxes.len() > 0);
debug!("TextRunScanner: scanning %u boxes for text runs...", inline.boxes.len()); debug!("TextRunScanner: scanning %u boxes for text runs...", inline.boxes.len());
@ -334,8 +334,7 @@ impl TextRunScanner {
debug!("------------------"); debug!("------------------");
debug!("--- Elem ranges: ---"); debug!("--- Elem ranges: ---");
let elems: &mut ElementMapping = &mut flow.inline().elems; for flow.inline().elems.eachi_mut |i: uint, nr: &NodeRange| {
for elems.eachi_mut |i: uint, nr: &NodeRange| {
debug!("%u: %? --> %s", i, nr.range, nr.node.debug_str()); () debug!("%u: %? --> %s", i, nr.range, nr.node.debug_str()); ()
} }
debug!("--------------------"); debug!("--------------------");
@ -386,43 +385,46 @@ impl LineboxScanner {
pub fn scan_for_lines(&mut self, ctx: &LayoutContext) { pub fn scan_for_lines(&mut self, ctx: &LayoutContext) {
self.reset_scanner(); self.reset_scanner();
let boxes = &mut self.flow.inline().boxes; { // FIXME: manually control borrow length
let mut i = 0u; let inline: &InlineFlowData = self.flow.inline();
let mut i = 0u;
loop { loop {
// acquire the next box to lay out from work list or box list // acquire the next box to lay out from work list or box list
let cur_box = if self.work_list.is_empty() { let cur_box = if self.work_list.is_empty() {
if i == boxes.len() { if i == inline.boxes.len() {
break break
}
let box = inline.boxes[i]; i += 1;
debug!("LineboxScanner: Working with box from box list: b%d", box.id());
box
} else {
let box = self.work_list.pop_front();
debug!("LineboxScanner: Working with box from work list: b%d", box.id());
box
};
let box_was_appended = self.try_append_to_line(ctx, cur_box);
if !box_was_appended {
debug!("LineboxScanner: Box wasn't appended, because line %u was full.",
self.line_spans.len());
self.flush_current_line();
} else {
debug!("LineboxScanner: appended a box to line %u", self.line_spans.len());
} }
let box = boxes[i]; i += 1; }
debug!("LineboxScanner: Working with box from box list: b%d", box.id());
box
} else {
let box = self.work_list.pop_front();
debug!("LineboxScanner: Working with box from work list: b%d", box.id());
box
};
let box_was_appended = self.try_append_to_line(ctx, cur_box); if self.pending_line.range.length() > 0 {
if !box_was_appended { debug!("LineboxScanner: Partially full linebox %u left at end of scanning.",
debug!("LineboxScanner: Box wasn't appended, because line %u was full.",
self.line_spans.len()); self.line_spans.len());
self.flush_current_line(); self.flush_current_line();
} else {
debug!("LineboxScanner: appended a box to line %u", self.line_spans.len());
} }
} }
if self.pending_line.range.length() > 0 { { // FIXME: scope the borrow
debug!("LineboxScanner: Partially full linebox %u left at end of scanning.", let inline: &mut InlineFlowData = self.flow.inline();
self.line_spans.len()); inline.elems.repair_for_box_changes(inline.boxes, self.new_boxes);
self.flush_current_line();
} }
let boxes = &mut self.flow.inline().boxes;
let elems = &mut self.flow.inline().elems;
elems.repair_for_box_changes(*boxes, self.new_boxes);
self.swap_out_results(); self.swap_out_results();
} }
@ -431,10 +433,9 @@ impl LineboxScanner {
self.line_spans.len(), self.line_spans.len(),
self.flow.id()); self.flow.id());
let inline_boxes = &mut self.flow.inline().boxes; let inline: &mut InlineFlowData = self.flow.inline();
util::swap(inline_boxes, &mut self.new_boxes); util::swap(&mut inline.boxes, &mut self.new_boxes);
let lines = &mut self.flow.inline().lines; util::swap(&mut inline.lines, &mut self.line_spans);
util::swap(lines, &mut self.line_spans);
} }
fn flush_current_line(&mut self) { fn flush_current_line(&mut self) {
@ -763,7 +764,6 @@ impl InlineFlowData {
// TODO: We can use font metrics directly instead of re-measuring for the // TODO: We can use font metrics directly instead of re-measuring for the
// bounding box. // bounding box.
TextRenderBoxClass(text_box) => { TextRenderBoxClass(text_box) => {
let text_box = &mut *text_box; // FIXME: borrow check workaround
let range = &text_box.text_data.range; let range = &text_box.text_data.range;
let run = &text_box.text_data.run; let run = &text_box.text_data.run;
let text_bounds = run.metrics_for_range(range).bounding_box; let text_bounds = run.metrics_for_range(range).bounding_box;
@ -814,7 +814,7 @@ impl InlineFlowData {
self.common.position.size.height = cur_y; self.common.position.size.height = cur_y;
} }
pub fn build_display_list_inline(&mut self, pub fn build_display_list_inline(&self,
builder: &DisplayListBuilder, builder: &DisplayListBuilder,
dirty: &Rect<Au>, dirty: &Rect<Au>,
offset: &Point2D<Au>, offset: &Point2D<Au>,