Skip to content

Commit

Permalink
Remove last methods from InlineFragmentMap
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanzab committed Jun 2, 2014
1 parent 2b23a2c commit fe8e0ac
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 43 deletions.
4 changes: 2 additions & 2 deletions src/components/main/layout/construct.rs
Expand Up @@ -185,7 +185,7 @@ impl InlineFragmentsAccumulator {

fn from_inline_node(node: &ThreadSafeLayoutNode) -> InlineFragmentsAccumulator {
let mut fragments = InlineFragments::new();
fragments.map.push(node.style().clone(), Range::empty());
fragments.push_range(node.style().clone(), Range::empty());
InlineFragmentsAccumulator {
fragments: fragments,
has_enclosing_range: true,
Expand All @@ -200,7 +200,7 @@ impl InlineFragmentsAccumulator {

if has_enclosing_range {
let len = FragmentIndex(fragments.len() as int);
fragments.map.get_mut(FragmentIndex(0)).range.extend_to(len);
fragments.get_mut_range(FragmentIndex(0)).range.extend_to(len);
}
fragments
}
Expand Down
79 changes: 38 additions & 41 deletions src/components/main/layout/inline.rs
Expand Up @@ -695,7 +695,9 @@ impl InlineFragments {

/// Pushes a new inline fragment.
pub fn push(&mut self, fragment: Fragment, style: Arc<ComputedValues>) {
self.map.push(style, Range::new(FragmentIndex(self.fragments.len() as int), FragmentIndex(1)));
self.map.list.push(InlineFragmentRange::new(
style, Range::new(FragmentIndex(self.fragments.len() as int), FragmentIndex(1)),
));
self.fragments.push(fragment)
}

Expand All @@ -706,7 +708,7 @@ impl InlineFragments {
map: other_map
} = other;
let adjustment = FragmentIndex(self.fragments.len() as int);
self.map.push_all(other_map, adjustment);
self.push_all_ranges(other_map, adjustment);
self.fragments.push_all_move(other_fragments);
}

Expand Down Expand Up @@ -737,6 +739,33 @@ impl InlineFragments {
self.fragments.get_mut(index)
}

/// Adds the given node to the fragment map.
pub fn push_range(&mut self, style: Arc<ComputedValues>, range: Range<FragmentIndex>) {
self.map.list.push(InlineFragmentRange::new(style, range))
}

/// Pushes the ranges in a fragment map, adjusting indices as necessary.
fn push_all_ranges(&mut self, other: InlineFragmentMap, adjustment: FragmentIndex) {
let InlineFragmentMap {
list: other_list
} = other;

for other_range in other_list.move_iter() {
let InlineFragmentRange {
style: other_style,
range: mut other_range
} = other_range;

other_range.shift_by(adjustment);
self.push_range(other_style, other_range)
}
}

/// Returns the range with the given index.
pub fn get_mut_range<'a>(&'a mut self, index: FragmentIndex) -> &'a mut InlineFragmentRange {
self.map.list.get_mut(index.to_uint())
}

/// Rebuilds the list after the fragments have been split or deleted (for example, for line
/// breaking). This assumes that the overall structure of the DOM has not changed; if the
/// DOM has changed, then the flow constructor will need to do more complicated surgery than
Expand Down Expand Up @@ -1370,44 +1399,6 @@ impl InlineFragmentMap {
list: Vec::new(),
}
}

/// Adds the given node to the fragment map.
pub fn push(&mut self, style: Arc<ComputedValues>, range: Range<FragmentIndex>) {
self.list.push(InlineFragmentRange::new(style, range))
}

/// Pushes the ranges in another fragment map onto the end of this one, adjusting indices as
/// necessary.
fn push_all(&mut self, other: InlineFragmentMap, adjustment: FragmentIndex) {
let InlineFragmentMap {
list: other_list
} = other;

for other_range in other_list.move_iter() {
let InlineFragmentRange {
style: other_style,
range: mut other_range
} = other_range;

other_range.shift_by(adjustment);
self.push(other_style, other_range)
}
}

/// Returns the range with the given index.
pub fn get_mut<'a>(&'a mut self, index: FragmentIndex) -> &'a mut InlineFragmentRange {
&mut self.list.as_mut_slice()[index.to_uint()]
}

/// Iterates over all ranges that contain the fragment with the given index, outermost first.
#[inline(always)]
fn ranges_for_index<'a>(&'a self, index: FragmentIndex) -> RangeIterator<'a> {
RangeIterator {
iter: self.list.as_slice().iter(),
index: index,
seen_first: false,
}
}
}

/// The context that an inline fragment appears in. This allows the fragment map to be passed in
Expand All @@ -1425,8 +1416,14 @@ impl<'a> InlineFragmentContext<'a> {
}
}

/// Iterates over all ranges that contain the fragment at context's index, outermost first.
#[inline(always)]
pub fn ranges(&self) -> RangeIterator<'a> {
self.map.ranges_for_index(self.index)
RangeIterator {
iter: self.map.list.iter(),
index: self.index,
seen_first: false,
}
}
}

Expand Down

0 comments on commit fe8e0ac

Please sign in to comment.