Skip to content
Permalink
Browse files

Make MutableRange freezable.

  • Loading branch information
Brian J. Burg
Brian J. Burg committed Nov 19, 2012
1 parent 25f019b commit 0562871cc77ce512498ef9d97a5919b673bcdd70
@@ -250,10 +250,10 @@ pub impl HarfbuzzShaper {
}

// some helpers
let glyph_span : MutableRange = range::empty_mut();
let mut glyph_span : MutableRange = range::empty_mut();
// this span contains first byte of first char, to last byte of last char in range.
// so, end() points to first byte of last+1 char, if it's less than byte_max.
let char_byte_span : MutableRange = range::empty_mut();
let mut char_byte_span : MutableRange = range::empty_mut();
let mut y_pos = Au(0);

// main loop over each glyph. each iteration usually processes 1 glyph and 1+ chars.
@@ -336,7 +336,7 @@ pub impl HarfbuzzShaper {
// gspan: [-]
// cspan: [-]
// covsp: [---------------]
let covered_byte_span = copy char_byte_span;
let mut covered_byte_span = copy char_byte_span;
// extend, clipping at end of text range.
while covered_byte_span.end() < byte_max
&& byteToGlyph[covered_byte_span.end()] == NO_GLYPH {
@@ -92,7 +92,7 @@ impl TextRun {
fn iter_natural_lines_for_range(&self, range: Range, f: fn(Range) -> bool) {
assert range.is_valid_for_string(self.text);

let clump = MutableRange::new(range.begin(), 0);
let mut clump = MutableRange::new(range.begin(), 0);
let mut in_clump = false;

// clump non-linebreaks of nonzero length
@@ -120,7 +120,7 @@ impl TextRun {
fn iter_indivisible_pieces_for_range(&self, range: Range, f: fn(Range) -> bool) {
assert range.is_valid_for_string(self.text);

let clump = MutableRange::new(range.begin(), 0);
let mut clump = MutableRange::new(range.begin(), 0);
loop {
// find next non-whitespace byte index, then clump all whitespace before it.
match str::find_between(self.text, clump.begin(), range.end(), |c| !char::is_whitespace(c)) {
@@ -106,8 +106,8 @@ pub impl Range {
pub pure fn empty_mut() -> MutableRange { MutableRange::new(0, 0) }

pub struct MutableRange {
priv mut off: uint,
priv mut len: uint
priv off: uint,
priv len: uint
}

pub impl MutableRange {
@@ -120,48 +120,48 @@ pub impl MutableRange {
}
}

impl MutableRange {
pub pure fn begin() -> uint { self.off }
pub pure fn length() -> uint { self.len }
pub pure fn end() -> uint { self.off + self.len }
pub pure fn eachi(cb: fn&(uint) -> bool) {
pub impl MutableRange {
pure fn begin(&const self) -> uint { self.off }
pure fn length(&const self) -> uint { self.len }
pure fn end(&const self) -> uint { self.off + self.len }
pure fn eachi(&const self, cb: fn&(uint) -> bool) {
do uint::range(self.off, self.off + self.len) |i| { cb(i) }
}

pub pure fn contains(i: uint) -> bool {
pure fn contains(&const self, i: uint) -> bool {
i >= self.begin() && i < self.end()
}

fn relation_to_range(&self, other: &MutableRange) -> RangeRelation {
fn relation_to_range(&const self, other: &MutableRange) -> RangeRelation {
self.as_immutable().relation_to_range(other.as_immutable())
}

pub pure fn as_immutable() -> Range {
pure fn as_immutable(&const self) -> Range {
Range(self.begin(), self.length())
}

pub pure fn is_valid_for_string(s: &str) -> bool {
pure fn is_valid_for_string(&const self, s: &str) -> bool {
self.begin() < s.len() && self.end() <= s.len() && self.length() <= s.len()
}

pub fn shift_by(i: int) {
fn shift_by(&mut self, i: int) {
self.off = ((self.off as int) + i) as uint;
}

pub fn extend_by(i: int) {
fn extend_by(&mut self, i: int) {
self.len = ((self.len as int) + i) as uint;
}

pub fn extend_to(i: uint) {
fn extend_to(&mut self, i: uint) {
self.len = i - self.off;
}

pub fn adjust_by(off_i: int, len_i: int) {
fn adjust_by(&mut self, off_i: int, len_i: int) {
self.off = ((self.off as int) + off_i) as uint;
self.len = ((self.len as int) + len_i) as uint;
}

pub fn reset(off_i: uint, len_i: uint) {
fn reset(&mut self, off_i: uint, len_i: uint) {
self.off = off_i;
self.len = len_i;
}
@@ -189,7 +189,7 @@ impl RenderBox : RenderBoxMethods {

let mut pieces_processed_count : uint = 0;
let mut remaining_width : Au = max_width;
let left_range = MutableRange::new(data.range.begin(), 0);
let mut left_range = MutableRange::new(data.range.begin(), 0);
let mut right_range : Option<Range> = None;
debug!("split_to_width: splitting text box (strlen=%u, range=%?, avail_width=%?)",
data.run.text.len(), data.range, max_width);
@@ -151,7 +151,7 @@ impl BoxGenerator {
self.flow.inline().boxes.push(*spacer);
}
}
let node_range: MutableRange = MutableRange::new(self.range_stack.pop(), 0);
let mut node_range: MutableRange = MutableRange::new(self.range_stack.pop(), 0);
node_range.extend_to(self.flow.inline().boxes.len());
assert node_range.length() > 0;

@@ -147,36 +147,36 @@ impl ElementMapping {

// stack-allocated object for scanning an inline flow into
// TextRun-containing TextBoxes.
struct TextRunScanner {
priv struct TextRunScanner {
clump: MutableRange,
flow: @FlowContext,
}

fn TextRunScanner(flow: @FlowContext) -> TextRunScanner {
TextRunScanner {
clump: MutableRange::empty(),
flow: flow,
priv impl TextRunScanner {
static fn new() -> TextRunScanner {
TextRunScanner {
clump: MutableRange::empty(),
}
}
}

impl TextRunScanner {
fn scan_for_runs(ctx: &LayoutContext) {
assert self.flow.inline().boxes.len() > 0;
priv impl TextRunScanner {
fn scan_for_runs(&mut self, ctx: &LayoutContext, flow: @FlowContext) {
assert flow.inline().boxes.len() > 0;

do self.flow.inline().boxes.swap |in_boxes| {
do flow.inline().boxes.swap |in_boxes| {
debug!("TextRunScanner: scanning %u boxes for text runs...", in_boxes.len());
let out_boxes = DVec();

for uint::range(0, in_boxes.len()) |box_i| {
debug!("TextRunScanner: considering box: %?", in_boxes[box_i].debug_str());
if box_i > 0 && !can_coalesce_text_nodes(in_boxes, box_i-1, box_i) {
self.flush_clump_to_list(ctx, in_boxes, &out_boxes);
self.flush_clump_to_list(ctx, flow, in_boxes, &out_boxes);
}
self.clump.extend_by(1);
}
// handle remaining clumps
if self.clump.length() > 0 {
self.flush_clump_to_list(ctx, in_boxes, &out_boxes);
self.flush_clump_to_list(ctx, flow, in_boxes, &out_boxes);
}

debug!("TextRunScanner: swapping out boxes.");
@@ -212,7 +212,9 @@ impl TextRunScanner {
// N.B. in_boxes is passed by reference, since we cannot
// recursively borrow or swap the flow's dvec of boxes. When all
// boxes are appended, the caller swaps the flow's box list.
fn flush_clump_to_list(ctx: &LayoutContext,
fn flush_clump_to_list(&mut self,
ctx: &LayoutContext,
flow: @FlowContext,
in_boxes: &[@RenderBox],
out_boxes: &DVec<@RenderBox>) {
assert self.clump.length() > 0;
@@ -285,7 +287,8 @@ impl TextRunScanner {
let fontgroup = ctx.font_ctx.get_resolved_font_for_style(&font_style);
let run = @TextRun::new(fontgroup.fonts[0], move run_str);
debug!("TextRunScanner: pushing box(es) in range: %?", self.clump);
for self.clump.eachi |i| {
let clump = self.clump;
for clump.eachi |i| {
let range = new_ranges[i - self.clump.begin()];
if range.length() == 0 {
error!("Elided an UnscannedTextbox because it was zero-length after compression; %s",
@@ -311,7 +314,7 @@ impl TextRunScanner {
debug!("------------------");

debug!("--- Elem ranges: ---");
for self.flow.inline().elems.eachi_mut |i: uint, nr: &NodeRange| {
for flow.inline().elems.eachi_mut |i: uint, nr: &NodeRange| {
debug!("%u: %? --> %s", i, nr.range, nr.node.debug_str()); ()
}
debug!("--------------------");
@@ -324,7 +327,7 @@ struct LineboxScanner {
flow: @FlowContext,
new_boxes: DVec<@RenderBox>,
work_list: DList<@RenderBox>,
pending_line: {range: MutableRange, mut width: Au},
pending_line: {mut range: MutableRange, mut width: Au},
line_spans: DVec<Range>,
}

@@ -335,7 +338,7 @@ fn LineboxScanner(inline: @FlowContext) -> LineboxScanner {
flow: inline,
new_boxes: DVec(),
work_list: DList(),
pending_line: {range: MutableRange::empty(), mut width: Au(0)},
pending_line: {mut range: MutableRange::empty(), mut width: Au(0)},
line_spans: DVec()
}
}
@@ -594,8 +597,8 @@ impl FlowContext : InlineLayout {
fn bubble_widths_inline(@self, ctx: &LayoutContext) {
assert self.starts_inline_flow();

let scanner = TextRunScanner(self);
scanner.scan_for_runs(ctx);
let mut scanner = TextRunScanner::new();
scanner.scan_for_runs(ctx, self);

let mut min_width = Au(0);
let mut pref_width = Au(0);
@@ -630,7 +633,7 @@ impl FlowContext : InlineLayout {
};
} // for boxes.each |box|

let scanner = LineboxScanner(self);
let mut scanner = LineboxScanner(self);
scanner.scan_for_lines(ctx);

/* There are no child contexts, so stop here. */

0 comments on commit 0562871

Please sign in to comment.
You can’t perform that action at this time.