зеркало из https://github.com/mozilla/gecko-dev.git
servo: Merge #2322 - Replace some ~[T] by Vec<T> (from Ms2ger:vec); r=jdm
Source-Repo: https://github.com/servo/servo Source-Revision: deacda7d225e0b57ec3b7fcebd741c185c111cec
This commit is contained in:
Родитель
be6b296acf
Коммит
24d211ff8e
|
@ -33,7 +33,7 @@ use text::{Shaper, TextRun};
|
||||||
// resources needed by the graphics layer to draw glyphs.
|
// resources needed by the graphics layer to draw glyphs.
|
||||||
|
|
||||||
pub trait FontHandleMethods {
|
pub trait FontHandleMethods {
|
||||||
fn new_from_buffer(fctx: &FontContextHandle, buf: ~[u8], style: &SpecifiedFontStyle)
|
fn new_from_buffer(fctx: &FontContextHandle, buf: Vec<u8>, style: &SpecifiedFontStyle)
|
||||||
-> Result<Self,()>;
|
-> Result<Self,()>;
|
||||||
|
|
||||||
// an identifier usable by FontContextHandle to recreate this FontHandle.
|
// an identifier usable by FontContextHandle to recreate this FontHandle.
|
||||||
|
@ -216,7 +216,7 @@ pub struct Font {
|
||||||
|
|
||||||
impl<'a> Font {
|
impl<'a> Font {
|
||||||
pub fn new_from_buffer(ctx: &FontContext,
|
pub fn new_from_buffer(ctx: &FontContext,
|
||||||
buffer: ~[u8],
|
buffer: Vec<u8>,
|
||||||
style: &SpecifiedFontStyle,
|
style: &SpecifiedFontStyle,
|
||||||
backend: BackendType)
|
backend: BackendType)
|
||||||
-> Result<Rc<RefCell<Font>>, ()> {
|
-> Result<Rc<RefCell<Font>>, ()> {
|
||||||
|
|
|
@ -47,7 +47,7 @@ impl FontTableMethods for FontTable {
|
||||||
}
|
}
|
||||||
|
|
||||||
enum FontSource {
|
enum FontSource {
|
||||||
FontSourceMem(~[u8]),
|
FontSourceMem(Vec<u8>),
|
||||||
FontSourceFile(~str)
|
FontSourceFile(~str)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ impl Drop for FontHandle {
|
||||||
|
|
||||||
impl FontHandleMethods for FontHandle {
|
impl FontHandleMethods for FontHandle {
|
||||||
fn new_from_buffer(fctx: &FontContextHandle,
|
fn new_from_buffer(fctx: &FontContextHandle,
|
||||||
buf: ~[u8],
|
buf: Vec<u8>,
|
||||||
style: &SpecifiedFontStyle)
|
style: &SpecifiedFontStyle)
|
||||||
-> Result<FontHandle, ()> {
|
-> Result<FontHandle, ()> {
|
||||||
let ft_ctx: FT_Library = fctx.ctx.ctx;
|
let ft_ctx: FT_Library = fctx.ctx.ctx;
|
||||||
|
|
|
@ -47,7 +47,7 @@ impl FontTableMethods for FontTable {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum FontSource {
|
pub enum FontSource {
|
||||||
FontSourceMem(~[u8]),
|
FontSourceMem(Vec<u8>),
|
||||||
FontSourceFile(~str)
|
FontSourceFile(~str)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ impl Drop for FontHandle {
|
||||||
|
|
||||||
impl FontHandleMethods for FontHandle {
|
impl FontHandleMethods for FontHandle {
|
||||||
fn new_from_buffer(fctx: &FontContextHandle,
|
fn new_from_buffer(fctx: &FontContextHandle,
|
||||||
buf: ~[u8],
|
buf: Vec<u8>,
|
||||||
style: &SpecifiedFontStyle)
|
style: &SpecifiedFontStyle)
|
||||||
-> Result<FontHandle, ()> {
|
-> Result<FontHandle, ()> {
|
||||||
let ft_ctx: FT_Library = fctx.ctx.ctx;
|
let ft_ctx: FT_Library = fctx.ctx.ctx;
|
||||||
|
|
|
@ -77,9 +77,9 @@ impl FontHandle {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FontHandleMethods for FontHandle {
|
impl FontHandleMethods for FontHandle {
|
||||||
fn new_from_buffer(_: &FontContextHandle, buf: ~[u8], style: &SpecifiedFontStyle)
|
fn new_from_buffer(_: &FontContextHandle, buf: Vec<u8>, style: &SpecifiedFontStyle)
|
||||||
-> Result<FontHandle, ()> {
|
-> Result<FontHandle, ()> {
|
||||||
let fontprov = CGDataProvider::from_buffer(buf);
|
let fontprov = CGDataProvider::from_buffer(buf.as_slice());
|
||||||
let cgfont = CGFont::from_data_provider(fontprov);
|
let cgfont = CGFont::from_data_provider(fontprov);
|
||||||
let ctfont = core_text::font::new_from_CGFont(&cgfont, style.pt_size);
|
let ctfont = core_text::font::new_from_CGFont(&cgfont, style.pt_size);
|
||||||
|
|
||||||
|
|
|
@ -467,7 +467,7 @@ pub enum GlyphInfo<'a> {
|
||||||
impl<'a> GlyphInfo<'a> {
|
impl<'a> GlyphInfo<'a> {
|
||||||
pub fn index(self) -> GlyphIndex {
|
pub fn index(self) -> GlyphIndex {
|
||||||
match self {
|
match self {
|
||||||
SimpleGlyphInfo(store, entry_i) => store.entry_buffer[entry_i].index(),
|
SimpleGlyphInfo(store, entry_i) => store.entry_buffer.get(entry_i).index(),
|
||||||
DetailGlyphInfo(store, entry_i, detail_j) => {
|
DetailGlyphInfo(store, entry_i, detail_j) => {
|
||||||
store.detail_store.get_detailed_glyph_with_index(entry_i, detail_j).index
|
store.detail_store.get_detailed_glyph_with_index(entry_i, detail_j).index
|
||||||
}
|
}
|
||||||
|
@ -478,7 +478,7 @@ impl<'a> GlyphInfo<'a> {
|
||||||
// FIXME: Resolution conflicts with IteratorUtil trait so adding trailing _
|
// FIXME: Resolution conflicts with IteratorUtil trait so adding trailing _
|
||||||
pub fn advance(self) -> Au {
|
pub fn advance(self) -> Au {
|
||||||
match self {
|
match self {
|
||||||
SimpleGlyphInfo(store, entry_i) => store.entry_buffer[entry_i].advance(),
|
SimpleGlyphInfo(store, entry_i) => store.entry_buffer.get(entry_i).advance(),
|
||||||
DetailGlyphInfo(store, entry_i, detail_j) => {
|
DetailGlyphInfo(store, entry_i, detail_j) => {
|
||||||
store.detail_store.get_detailed_glyph_with_index(entry_i, detail_j).advance
|
store.detail_store.get_detailed_glyph_with_index(entry_i, detail_j).advance
|
||||||
}
|
}
|
||||||
|
@ -499,7 +499,7 @@ impl<'a> GlyphInfo<'a> {
|
||||||
pub struct GlyphStore {
|
pub struct GlyphStore {
|
||||||
// TODO(pcwalton): Allocation of this buffer is expensive. Consider a small-vector
|
// TODO(pcwalton): Allocation of this buffer is expensive. Consider a small-vector
|
||||||
// optimization.
|
// optimization.
|
||||||
entry_buffer: ~[GlyphEntry],
|
entry_buffer: Vec<GlyphEntry>,
|
||||||
|
|
||||||
detail_store: DetailedGlyphStore,
|
detail_store: DetailedGlyphStore,
|
||||||
|
|
||||||
|
@ -513,7 +513,7 @@ impl<'a> GlyphStore {
|
||||||
assert!(length > 0);
|
assert!(length > 0);
|
||||||
|
|
||||||
GlyphStore {
|
GlyphStore {
|
||||||
entry_buffer: slice::from_elem(length, GlyphEntry::initial()),
|
entry_buffer: Vec::from_elem(length, GlyphEntry::initial()),
|
||||||
detail_store: DetailedGlyphStore::new(),
|
detail_store: DetailedGlyphStore::new(),
|
||||||
is_whitespace: is_whitespace,
|
is_whitespace: is_whitespace,
|
||||||
}
|
}
|
||||||
|
@ -550,9 +550,9 @@ impl<'a> GlyphStore {
|
||||||
self.detail_store.add_detailed_glyphs_for_entry(i, glyph);
|
self.detail_store.add_detailed_glyphs_for_entry(i, glyph);
|
||||||
GlyphEntry::complex(data.cluster_start, data.ligature_start, 1)
|
GlyphEntry::complex(data.cluster_start, data.ligature_start, 1)
|
||||||
}
|
}
|
||||||
}.adapt_character_flags_of_entry(self.entry_buffer[i]);
|
}.adapt_character_flags_of_entry(*self.entry_buffer.get(i));
|
||||||
|
|
||||||
self.entry_buffer[i] = entry;
|
*self.entry_buffer.get_mut(i) = entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_glyphs_for_char_index(&mut self, i: uint, data_for_glyphs: &[GlyphData]) {
|
pub fn add_glyphs_for_char_index(&mut self, i: uint, data_for_glyphs: &[GlyphData]) {
|
||||||
|
@ -576,11 +576,11 @@ impl<'a> GlyphStore {
|
||||||
first_glyph_data.ligature_start,
|
first_glyph_data.ligature_start,
|
||||||
glyph_count)
|
glyph_count)
|
||||||
}
|
}
|
||||||
}.adapt_character_flags_of_entry(self.entry_buffer[i]);
|
}.adapt_character_flags_of_entry(*self.entry_buffer.get(i));
|
||||||
|
|
||||||
debug!("Adding multiple glyphs[idx={:u}, count={:u}]: {:?}", i, glyph_count, entry);
|
debug!("Adding multiple glyphs[idx={:u}, count={:u}]: {:?}", i, glyph_count, entry);
|
||||||
|
|
||||||
self.entry_buffer[i] = entry;
|
*self.entry_buffer.get_mut(i) = entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
// used when a character index has no associated glyph---for example, a ligature continuation.
|
// used when a character index has no associated glyph---for example, a ligature continuation.
|
||||||
|
@ -590,7 +590,7 @@ impl<'a> GlyphStore {
|
||||||
let entry = GlyphEntry::complex(cluster_start, ligature_start, 0);
|
let entry = GlyphEntry::complex(cluster_start, ligature_start, 0);
|
||||||
debug!("adding spacer for chracter without associated glyph[idx={:u}]", i);
|
debug!("adding spacer for chracter without associated glyph[idx={:u}]", i);
|
||||||
|
|
||||||
self.entry_buffer[i] = entry;
|
*self.entry_buffer.get_mut(i) = entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn iter_glyphs_for_char_index(&'a self, i: uint) -> GlyphIterator<'a> {
|
pub fn iter_glyphs_for_char_index(&'a self, i: uint) -> GlyphIterator<'a> {
|
||||||
|
@ -617,57 +617,57 @@ impl<'a> GlyphStore {
|
||||||
// getter methods
|
// getter methods
|
||||||
pub fn char_is_space(&self, i: uint) -> bool {
|
pub fn char_is_space(&self, i: uint) -> bool {
|
||||||
assert!(i < self.entry_buffer.len());
|
assert!(i < self.entry_buffer.len());
|
||||||
self.entry_buffer[i].char_is_space()
|
self.entry_buffer.get(i).char_is_space()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn char_is_tab(&self, i: uint) -> bool {
|
pub fn char_is_tab(&self, i: uint) -> bool {
|
||||||
assert!(i < self.entry_buffer.len());
|
assert!(i < self.entry_buffer.len());
|
||||||
self.entry_buffer[i].char_is_tab()
|
self.entry_buffer.get(i).char_is_tab()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn char_is_newline(&self, i: uint) -> bool {
|
pub fn char_is_newline(&self, i: uint) -> bool {
|
||||||
assert!(i < self.entry_buffer.len());
|
assert!(i < self.entry_buffer.len());
|
||||||
self.entry_buffer[i].char_is_newline()
|
self.entry_buffer.get(i).char_is_newline()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_ligature_start(&self, i: uint) -> bool {
|
pub fn is_ligature_start(&self, i: uint) -> bool {
|
||||||
assert!(i < self.entry_buffer.len());
|
assert!(i < self.entry_buffer.len());
|
||||||
self.entry_buffer[i].is_ligature_start()
|
self.entry_buffer.get(i).is_ligature_start()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_cluster_start(&self, i: uint) -> bool {
|
pub fn is_cluster_start(&self, i: uint) -> bool {
|
||||||
assert!(i < self.entry_buffer.len());
|
assert!(i < self.entry_buffer.len());
|
||||||
self.entry_buffer[i].is_cluster_start()
|
self.entry_buffer.get(i).is_cluster_start()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn can_break_before(&self, i: uint) -> BreakType {
|
pub fn can_break_before(&self, i: uint) -> BreakType {
|
||||||
assert!(i < self.entry_buffer.len());
|
assert!(i < self.entry_buffer.len());
|
||||||
self.entry_buffer[i].can_break_before()
|
self.entry_buffer.get(i).can_break_before()
|
||||||
}
|
}
|
||||||
|
|
||||||
// setter methods
|
// setter methods
|
||||||
pub fn set_char_is_space(&mut self, i: uint) {
|
pub fn set_char_is_space(&mut self, i: uint) {
|
||||||
assert!(i < self.entry_buffer.len());
|
assert!(i < self.entry_buffer.len());
|
||||||
let entry = self.entry_buffer[i];
|
let entry = *self.entry_buffer.get(i);
|
||||||
self.entry_buffer[i] = entry.set_char_is_space();
|
*self.entry_buffer.get_mut(i) = entry.set_char_is_space();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_char_is_tab(&mut self, i: uint) {
|
pub fn set_char_is_tab(&mut self, i: uint) {
|
||||||
assert!(i < self.entry_buffer.len());
|
assert!(i < self.entry_buffer.len());
|
||||||
let entry = self.entry_buffer[i];
|
let entry = *self.entry_buffer.get(i);
|
||||||
self.entry_buffer[i] = entry.set_char_is_tab();
|
*self.entry_buffer.get_mut(i) = entry.set_char_is_tab();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_char_is_newline(&mut self, i: uint) {
|
pub fn set_char_is_newline(&mut self, i: uint) {
|
||||||
assert!(i < self.entry_buffer.len());
|
assert!(i < self.entry_buffer.len());
|
||||||
let entry = self.entry_buffer[i];
|
let entry = *self.entry_buffer.get(i);
|
||||||
self.entry_buffer[i] = entry.set_char_is_newline();
|
*self.entry_buffer.get_mut(i) = entry.set_char_is_newline();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_can_break_before(&mut self, i: uint, t: BreakType) {
|
pub fn set_can_break_before(&mut self, i: uint, t: BreakType) {
|
||||||
assert!(i < self.entry_buffer.len());
|
assert!(i < self.entry_buffer.len());
|
||||||
let entry = self.entry_buffer[i];
|
let entry = *self.entry_buffer.get(i);
|
||||||
self.entry_buffer[i] = entry.set_can_break_before(t);
|
*self.entry_buffer.get_mut(i) = entry.set_can_break_before(t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -722,7 +722,7 @@ impl<'a> Iterator<(uint, GlyphInfo<'a>)> for GlyphIterator<'a> {
|
||||||
Some(i) => {
|
Some(i) => {
|
||||||
self.char_index = i;
|
self.char_index = i;
|
||||||
assert!(i < self.store.entry_buffer.len());
|
assert!(i < self.store.entry_buffer.len());
|
||||||
let entry = &self.store.entry_buffer[i];
|
let entry = self.store.entry_buffer.get(i);
|
||||||
if entry.is_simple() {
|
if entry.is_simple() {
|
||||||
Some((self.char_index, SimpleGlyphInfo(self.store, i)))
|
Some((self.char_index, SimpleGlyphInfo(self.store, i)))
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -76,7 +76,7 @@ impl Clone for ChildFrameTree {
|
||||||
|
|
||||||
pub struct SendableFrameTree {
|
pub struct SendableFrameTree {
|
||||||
pub pipeline: CompositionPipeline,
|
pub pipeline: CompositionPipeline,
|
||||||
pub children: ~[SendableChildFrameTree],
|
pub children: Vec<SendableChildFrameTree>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct SendableChildFrameTree {
|
pub struct SendableChildFrameTree {
|
||||||
|
@ -133,7 +133,7 @@ impl FrameTreeTraversal for Rc<FrameTree> {
|
||||||
|
|
||||||
fn iter(&self) -> FrameTreeIterator {
|
fn iter(&self) -> FrameTreeIterator {
|
||||||
FrameTreeIterator {
|
FrameTreeIterator {
|
||||||
stack: ~[self.clone()],
|
stack: vec!(self.clone()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -151,7 +151,7 @@ impl ChildFrameTree {
|
||||||
/// Note that this iterator should _not_ be used to mutate nodes _during_
|
/// Note that this iterator should _not_ be used to mutate nodes _during_
|
||||||
/// iteration. Mutating nodes once the iterator is out of scope is OK.
|
/// iteration. Mutating nodes once the iterator is out of scope is OK.
|
||||||
struct FrameTreeIterator {
|
struct FrameTreeIterator {
|
||||||
stack: ~[Rc<FrameTree>],
|
stack: Vec<Rc<FrameTree>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Iterator<Rc<FrameTree>> for FrameTreeIterator {
|
impl Iterator<Rc<FrameTree>> for FrameTreeIterator {
|
||||||
|
@ -220,7 +220,7 @@ impl NavigationContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the frame trees whose keys are pipeline_id.
|
/// Returns the frame trees whose keys are pipeline_id.
|
||||||
fn find_all(&mut self, pipeline_id: PipelineId) -> ~[Rc<FrameTree>] {
|
fn find_all(&mut self, pipeline_id: PipelineId) -> Vec<Rc<FrameTree>> {
|
||||||
let from_current = self.current.iter().filter_map(|frame_tree| {
|
let from_current = self.current.iter().filter_map(|frame_tree| {
|
||||||
frame_tree.find(pipeline_id)
|
frame_tree.find(pipeline_id)
|
||||||
});
|
});
|
||||||
|
@ -300,7 +300,7 @@ impl Constellation {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns both the navigation context and pending frame trees whose keys are pipeline_id.
|
/// Returns both the navigation context and pending frame trees whose keys are pipeline_id.
|
||||||
fn find_all(&mut self, pipeline_id: PipelineId) -> ~[Rc<FrameTree>] {
|
fn find_all(&mut self, pipeline_id: PipelineId) -> Vec<Rc<FrameTree>> {
|
||||||
let matching_navi_frames = self.navigation_context.find_all(pipeline_id);
|
let matching_navi_frames = self.navigation_context.find_all(pipeline_id);
|
||||||
let matching_pending_frames = self.pending_frames.iter().filter_map(|frame_change| {
|
let matching_pending_frames = self.pending_frames.iter().filter_map(|frame_change| {
|
||||||
frame_change.after.find(pipeline_id)
|
frame_change.after.find(pipeline_id)
|
||||||
|
@ -548,7 +548,7 @@ impl Constellation {
|
||||||
// or a new url entered.
|
// or a new url entered.
|
||||||
// Start by finding the frame trees matching the pipeline id,
|
// Start by finding the frame trees matching the pipeline id,
|
||||||
// and add the new pipeline to their sub frames.
|
// and add the new pipeline to their sub frames.
|
||||||
let frame_trees: ~[Rc<FrameTree>] = {
|
let frame_trees: Vec<Rc<FrameTree>> = {
|
||||||
let matching_navi_frames = self.navigation_context.find_all(source_pipeline_id);
|
let matching_navi_frames = self.navigation_context.find_all(source_pipeline_id);
|
||||||
let matching_pending_frames = self.pending_frames.iter().filter_map(|frame_change| {
|
let matching_pending_frames = self.pending_frames.iter().filter_map(|frame_change| {
|
||||||
frame_change.after.find(source_pipeline_id)
|
frame_change.after.find(source_pipeline_id)
|
||||||
|
|
|
@ -170,69 +170,6 @@ impl InlineBlockSplit {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Methods on optional vectors.
|
|
||||||
///
|
|
||||||
/// TODO(pcwalton): I think this will no longer be necessary once Rust #8981 lands.
|
|
||||||
pub trait OptVector<T> {
|
|
||||||
/// Turns this optional vector into an owned one. If the optional vector is `None`, then this
|
|
||||||
/// simply returns an empty owned vector.
|
|
||||||
fn to_vec(self) -> ~[T];
|
|
||||||
|
|
||||||
/// Pushes a value onto this vector.
|
|
||||||
fn push(&mut self, value: T);
|
|
||||||
|
|
||||||
/// Pushes a vector onto this vector, consuming the original.
|
|
||||||
fn push_all_move(&mut self, values: ~[T]);
|
|
||||||
|
|
||||||
/// Pushes an optional vector onto this vector, consuming the original.
|
|
||||||
fn push_opt_vec_move(&mut self, values: Self);
|
|
||||||
|
|
||||||
/// Returns the length of this optional vector.
|
|
||||||
fn len(&self) -> uint;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> OptVector<T> for Option<~[T]> {
|
|
||||||
#[inline]
|
|
||||||
fn to_vec(self) -> ~[T] {
|
|
||||||
match self {
|
|
||||||
None => ~[],
|
|
||||||
Some(vector) => vector,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn push(&mut self, value: T) {
|
|
||||||
match *self {
|
|
||||||
None => *self = Some(~[value]),
|
|
||||||
Some(ref mut vector) => vector.push(value),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn push_all_move(&mut self, values: ~[T]) {
|
|
||||||
match *self {
|
|
||||||
None => *self = Some(values),
|
|
||||||
Some(ref mut vector) => vector.push_all_move(values),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn push_opt_vec_move(&mut self, values: Option<~[T]>) {
|
|
||||||
match values {
|
|
||||||
None => {}
|
|
||||||
Some(values) => self.push_all_move(values),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn len(&self) -> uint {
|
|
||||||
match *self {
|
|
||||||
None => 0,
|
|
||||||
Some(ref vector) => vector.len(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Holds inline boxes that we're gathering for children of an inline node.
|
/// Holds inline boxes that we're gathering for children of an inline node.
|
||||||
struct InlineBoxAccumulator {
|
struct InlineBoxAccumulator {
|
||||||
/// The list of boxes.
|
/// The list of boxes.
|
||||||
|
|
|
@ -80,11 +80,11 @@ impl<'a> Hash for LowercaseAsciiString<'a> {
|
||||||
struct SelectorMap {
|
struct SelectorMap {
|
||||||
// TODO: Tune the initial capacity of the HashMap
|
// TODO: Tune the initial capacity of the HashMap
|
||||||
// FIXME: Use interned strings
|
// FIXME: Use interned strings
|
||||||
id_hash: HashMap<DOMString, ~[Rule]>,
|
id_hash: HashMap<DOMString, Vec<Rule>>,
|
||||||
class_hash: HashMap<DOMString, ~[Rule]>,
|
class_hash: HashMap<DOMString, Vec<Rule>>,
|
||||||
element_hash: HashMap<DOMString, ~[Rule]>,
|
element_hash: HashMap<DOMString, Vec<Rule>>,
|
||||||
// For Rules that don't have ID, class, or element selectors.
|
// For Rules that don't have ID, class, or element selectors.
|
||||||
universal_rules: ~[Rule],
|
universal_rules: Vec<Rule>,
|
||||||
/// Whether this hash is empty.
|
/// Whether this hash is empty.
|
||||||
empty: bool,
|
empty: bool,
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ impl SelectorMap {
|
||||||
id_hash: HashMap::new(),
|
id_hash: HashMap::new(),
|
||||||
class_hash: HashMap::new(),
|
class_hash: HashMap::new(),
|
||||||
element_hash: HashMap::new(),
|
element_hash: HashMap::new(),
|
||||||
universal_rules: ~[],
|
universal_rules: vec!(),
|
||||||
empty: true,
|
empty: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -151,7 +151,7 @@ impl SelectorMap {
|
||||||
shareable);
|
shareable);
|
||||||
|
|
||||||
SelectorMap::get_matching_rules(node,
|
SelectorMap::get_matching_rules(node,
|
||||||
self.universal_rules,
|
self.universal_rules.as_slice(),
|
||||||
matching_rules_list,
|
matching_rules_list,
|
||||||
shareable);
|
shareable);
|
||||||
|
|
||||||
|
@ -163,13 +163,13 @@ impl SelectorMap {
|
||||||
N:TNode<E>,
|
N:TNode<E>,
|
||||||
V:SmallVec<MatchedProperty>>(
|
V:SmallVec<MatchedProperty>>(
|
||||||
node: &N,
|
node: &N,
|
||||||
hash: &HashMap<DOMString,~[Rule]>,
|
hash: &HashMap<DOMString, Vec<Rule>>,
|
||||||
key: &str,
|
key: &str,
|
||||||
matching_rules: &mut V,
|
matching_rules: &mut V,
|
||||||
shareable: &mut bool) {
|
shareable: &mut bool) {
|
||||||
match hash.find_equiv(&key) {
|
match hash.find_equiv(&key) {
|
||||||
Some(rules) => {
|
Some(rules) => {
|
||||||
SelectorMap::get_matching_rules(node, *rules, matching_rules, shareable)
|
SelectorMap::get_matching_rules(node, rules.as_slice(), matching_rules, shareable)
|
||||||
}
|
}
|
||||||
None => {}
|
None => {}
|
||||||
}
|
}
|
||||||
|
@ -179,13 +179,13 @@ impl SelectorMap {
|
||||||
N:TNode<E>,
|
N:TNode<E>,
|
||||||
V:SmallVec<MatchedProperty>>(
|
V:SmallVec<MatchedProperty>>(
|
||||||
node: &N,
|
node: &N,
|
||||||
hash: &HashMap<DOMString,~[Rule]>,
|
hash: &HashMap<DOMString, Vec<Rule>>,
|
||||||
key: &str,
|
key: &str,
|
||||||
matching_rules: &mut V,
|
matching_rules: &mut V,
|
||||||
shareable: &mut bool) {
|
shareable: &mut bool) {
|
||||||
match hash.find_equiv(&LowercaseAsciiString(key)) {
|
match hash.find_equiv(&LowercaseAsciiString(key)) {
|
||||||
Some(rules) => {
|
Some(rules) => {
|
||||||
SelectorMap::get_matching_rules(node, *rules, matching_rules, shareable)
|
SelectorMap::get_matching_rules(node, rules.as_slice(), matching_rules, shareable)
|
||||||
}
|
}
|
||||||
None => {}
|
None => {}
|
||||||
}
|
}
|
||||||
|
@ -221,7 +221,7 @@ impl SelectorMap {
|
||||||
}
|
}
|
||||||
None => {}
|
None => {}
|
||||||
}
|
}
|
||||||
self.id_hash.insert(id_name, ~[rule]);
|
self.id_hash.insert(id_name, vec!(rule));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
None => {}
|
None => {}
|
||||||
|
@ -235,7 +235,7 @@ impl SelectorMap {
|
||||||
}
|
}
|
||||||
None => {}
|
None => {}
|
||||||
}
|
}
|
||||||
self.class_hash.insert(class_name, ~[rule]);
|
self.class_hash.insert(class_name, vec!(rule));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
None => {}
|
None => {}
|
||||||
|
@ -250,7 +250,7 @@ impl SelectorMap {
|
||||||
}
|
}
|
||||||
None => {}
|
None => {}
|
||||||
}
|
}
|
||||||
self.element_hash.insert(element_name, ~[rule]);
|
self.element_hash.insert(element_name, vec!(rule));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
None => {}
|
None => {}
|
||||||
|
@ -947,7 +947,7 @@ mod tests {
|
||||||
|
|
||||||
/// Helper method to get some Rules from selector strings.
|
/// Helper method to get some Rules from selector strings.
|
||||||
/// Each sublist of the result contains the Rules for one StyleRule.
|
/// Each sublist of the result contains the Rules for one StyleRule.
|
||||||
fn get_mock_rules(css_selectors: &[&str]) -> ~[~[Rule]] {
|
fn get_mock_rules(css_selectors: &[&str]) -> Vec<Vec<Rule>> {
|
||||||
use namespaces::NamespaceMap;
|
use namespaces::NamespaceMap;
|
||||||
use selectors::parse_selector_list;
|
use selectors::parse_selector_list;
|
||||||
use cssparser::tokenize;
|
use cssparser::tokenize;
|
||||||
|
@ -971,42 +971,42 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_rule_ordering_same_specificity(){
|
fn test_rule_ordering_same_specificity(){
|
||||||
let rules_list = get_mock_rules(["a.intro", "img.sidebar"]);
|
let rules_list = get_mock_rules(["a.intro", "img.sidebar"]);
|
||||||
let rule1 = rules_list[0][0].clone();
|
let rule1 = rules_list.get(0).get(0).clone();
|
||||||
let rule2 = rules_list[1][0].clone();
|
let rule2 = rules_list.get(1).get(0).clone();
|
||||||
assert!(rule1.property < rule2.property, "The rule that comes later should win.");
|
assert!(rule1.property < rule2.property, "The rule that comes later should win.");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_get_id_name(){
|
fn test_get_id_name(){
|
||||||
let rules_list = get_mock_rules([".intro", "#top"]);
|
let rules_list = get_mock_rules([".intro", "#top"]);
|
||||||
assert_eq!(SelectorMap::get_id_name(&rules_list[0][0]), None);
|
assert_eq!(SelectorMap::get_id_name(rules_list.get(0).get(0)), None);
|
||||||
assert_eq!(SelectorMap::get_id_name(&rules_list[1][0]), Some("top".to_owned()));
|
assert_eq!(SelectorMap::get_id_name(rules_list.get(1).get(0)), Some("top".to_owned()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_get_class_name(){
|
fn test_get_class_name(){
|
||||||
let rules_list = get_mock_rules([".intro.foo", "#top"]);
|
let rules_list = get_mock_rules([".intro.foo", "#top"]);
|
||||||
assert_eq!(SelectorMap::get_class_name(&rules_list[0][0]), Some("intro".to_owned()));
|
assert_eq!(SelectorMap::get_class_name(rules_list.get(0).get(0)), Some("intro".to_owned()));
|
||||||
assert_eq!(SelectorMap::get_class_name(&rules_list[1][0]), None);
|
assert_eq!(SelectorMap::get_class_name(rules_list.get(1).get(0)), None);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_get_element_name(){
|
fn test_get_element_name(){
|
||||||
let rules_list = get_mock_rules(["img.foo", "#top", "IMG", "ImG"]);
|
let rules_list = get_mock_rules(["img.foo", "#top", "IMG", "ImG"]);
|
||||||
assert_eq!(SelectorMap::get_element_name(&rules_list[0][0]), Some("img".to_owned()));
|
assert_eq!(SelectorMap::get_element_name(rules_list.get(0).get(0)), Some("img".to_owned()));
|
||||||
assert_eq!(SelectorMap::get_element_name(&rules_list[1][0]), None);
|
assert_eq!(SelectorMap::get_element_name(rules_list.get(1).get(0)), None);
|
||||||
assert_eq!(SelectorMap::get_element_name(&rules_list[2][0]), Some("img".to_owned()));
|
assert_eq!(SelectorMap::get_element_name(rules_list.get(2).get(0)), Some("img".to_owned()));
|
||||||
assert_eq!(SelectorMap::get_element_name(&rules_list[3][0]), Some("img".to_owned()));
|
assert_eq!(SelectorMap::get_element_name(rules_list.get(3).get(0)), Some("img".to_owned()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_insert(){
|
fn test_insert(){
|
||||||
let rules_list = get_mock_rules([".intro.foo", "#top"]);
|
let rules_list = get_mock_rules([".intro.foo", "#top"]);
|
||||||
let mut selector_map = SelectorMap::new();
|
let mut selector_map = SelectorMap::new();
|
||||||
selector_map.insert(rules_list[1][0].clone());
|
selector_map.insert(rules_list.get(1).get(0).clone());
|
||||||
assert_eq!(1, selector_map.id_hash.find_equiv(& &"top").unwrap()[0].property.source_order);
|
assert_eq!(1, selector_map.id_hash.find_equiv(& &"top").unwrap().get(0).property.source_order);
|
||||||
selector_map.insert(rules_list[0][0].clone());
|
selector_map.insert(rules_list.get(0).get(0).clone());
|
||||||
assert_eq!(0, selector_map.class_hash.find_equiv(& &"intro").unwrap()[0].property.source_order);
|
assert_eq!(0, selector_map.class_hash.find_equiv(& &"intro").unwrap().get(0).property.source_order);
|
||||||
assert!(selector_map.class_hash.find_equiv(& &"foo").is_none());
|
assert!(selector_map.class_hash.find_equiv(& &"foo").is_none());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче