Rust upgrade to rustc hash b03a2755193cd756583bcf5831cf4545d75ecb8a

This commit is contained in:
Jack Moffitt 2014-11-05 12:33:11 -07:00 committed by Glenn Watson
parent 26045d7fcb
commit d1b433a3b3
160 changed files with 1427 additions and 1162 deletions

View file

@ -2,7 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use std::collections::hashmap::HashMap;
use std::collections::HashMap;
use std::collections::hash_map::{Occupied, Vacant};
use geom::size::Size2D;
use layers::platform::surface::NativePaintingGraphicsContext;
use layers::layers::LayerBuffer;
@ -85,10 +86,17 @@ impl BufferMap {
self.mem += new_buffer.get_mem();
// use lazy insertion function to prevent unnecessary allocation
let counter = &self.counter;
self.map.find_or_insert_with(new_key, |_| BufferValue {
buffers: vec!(),
last_action: *counter
}).buffers.push(new_buffer);
match self.map.entry(new_key) {
Occupied(entry) => {
entry.into_mut().buffers.push(new_buffer);
}
Vacant(entry) => {
entry.set(BufferValue {
buffers: vec!(new_buffer),
last_action: *counter,
});
}
}
let mut opt_key: Option<BufferKey> = None;
while self.mem > self.max_mem {
@ -97,19 +105,19 @@ impl BufferMap {
None => {
match self.map.iter().min_by(|&(_, x)| x.last_action) {
Some((k, _)) => *k,
None => fail!("BufferMap: tried to delete with no elements in map"),
None => panic!("BufferMap: tried to delete with no elements in map"),
}
}
};
if {
let list = &mut self.map.get_mut(&old_key).buffers;
let list = &mut self.map[old_key].buffers;
let condemned_buffer = list.pop().take().unwrap();
self.mem -= condemned_buffer.get_mem();
condemned_buffer.destroy(graphics_context);
list.is_empty()
}
{ // then
self.map.pop(&old_key); // Don't store empty vectors!
self.map.remove(&old_key); // Don't store empty vectors!
opt_key = None;
} else {
opt_key = Some(old_key);
@ -121,7 +129,7 @@ impl BufferMap {
pub fn find(&mut self, size: Size2D<uint>) -> Option<Box<LayerBuffer>> {
let mut flag = false; // True if key needs to be popped after retrieval.
let key = BufferKey::get(size);
let ret = match self.map.find_mut(&key) {
let ret = match self.map.get_mut(&key) {
Some(ref mut buffer_val) => {
buffer_val.last_action = self.counter;
self.counter += 1;
@ -137,7 +145,7 @@ impl BufferMap {
};
if flag {
self.map.pop(&key); // Don't store empty vectors!
self.map.remove(&key); // Don't store empty vectors!
}
ret

View file

@ -20,7 +20,6 @@ use text::glyph::CharIndex;
use text::TextRun;
use azure::azure::AzFloat;
use collections::Deque;
use collections::dlist::{mod, DList};
use geom::{Point2D, Rect, SideOffsets2D, Size2D, Matrix2D};
use libc::uintptr_t;
@ -188,7 +187,7 @@ impl DisplayList {
/// Appends the given item to the display list.
#[inline]
pub fn push(&mut self, item: DisplayItem) {
self.list.push(item);
self.list.push_back(item);
}
/// Appends the items in the given display list to this one, removing them in the process.
@ -476,7 +475,7 @@ impl DisplayItem {
}
ImageDisplayItemClass(ref image_item) => {
debug!("Drawing image at {:?}.", image_item.base.bounds);
debug!("Drawing image at {}.", image_item.base.bounds);
let mut y_offset = Au(0);
while y_offset < image_item.base.bounds.size.height {

View file

@ -33,7 +33,7 @@ impl DisplayListOptimizer {
for item in display_list.iter() {
match self.process_display_item(item) {
None => {}
Some(display_item) => result.push(display_item),
Some(display_item) => result.push_back(display_item),
}
}
DisplayList {
@ -51,4 +51,3 @@ impl DisplayListOptimizer {
}
}
}

View file

@ -68,7 +68,7 @@ pub trait FontTableMethods {
fn with_buffer(&self, |*const u8, uint|);
}
#[deriving(Clone)]
#[deriving(Clone, Show)]
pub struct FontMetrics {
pub underline_size: Au,
pub underline_offset: Au,
@ -103,7 +103,7 @@ impl Font {
pub fn shape_text(&mut self, text: &str, is_whitespace: bool) -> Arc<GlyphStore> {
self.make_shaper();
let shaper = &self.shaper;
match self.shape_cache.find_equiv(&text) {
match self.shape_cache.find_equiv(text) {
None => {}
Some(glyphs) => return (*glyphs).clone(),
}

View file

@ -133,7 +133,7 @@ impl FontCache {
let maybe_resource = load_whole_resource(&self.resource_task, url.clone());
match maybe_resource {
Ok((_, bytes)) => {
let family = self.web_families.get_mut(&family_name);
let family = &mut self.web_families[family_name];
family.add_template(url.to_string().as_slice(), Some(bytes));
},
Err(_) => {
@ -142,7 +142,7 @@ impl FontCache {
}
}
LocalSource(ref local_family_name) => {
let family = self.web_families.get_mut(&family_name);
let family = &mut self.web_families[family_name];
get_variations_for_family(local_family_name.as_slice(), |path| {
family.add_template(path.as_slice(), None);
});
@ -170,7 +170,7 @@ impl FontCache {
}
fn transform_family(&self, family: &LowercaseString) -> LowercaseString {
match self.generic_fonts.find(family) {
match self.generic_fonts.get(family) {
None => family.clone(),
Some(mapped_family) => (*mapped_family).clone()
}
@ -182,7 +182,7 @@ impl FontCache {
// look up canonical name
if self.local_families.contains_key(family_name) {
debug!("FontList: Found font family with name={:s}", family_name.to_string());
let s = self.local_families.get_mut(family_name);
let s = &mut self.local_families[*family_name];
if s.templates.len() == 0 {
get_variations_for_family(family_name.as_slice(), |path| {
@ -207,7 +207,7 @@ impl FontCache {
fn find_font_in_web_family<'a>(&'a mut self, family_name: &LowercaseString, desc: &FontTemplateDescriptor)
-> Option<Arc<FontTemplateData>> {
if self.web_families.contains_key(family_name) {
let family = self.web_families.get_mut(family_name);
let family = &mut self.web_families[*family_name];
let maybe_font = family.find_font_for_style(desc, &self.font_context);
maybe_font
} else {
@ -237,7 +237,7 @@ impl FontCache {
}
}
fail!("Unable to find any fonts that match (do you have fallback fonts installed?)");
panic!("Unable to find any fonts that match (do you have fallback fonts installed?)");
}
}

View file

@ -25,12 +25,10 @@ use azure::AzFloat;
use azure::azure_hl::SkiaBackend;
use azure::scaled_font::ScaledFont;
#[cfg(target_os="linux")]
#[cfg(target_os="android")]
#[cfg(any(target_os="linux", target_os = "android"))]
use azure::scaled_font::FontData;
#[cfg(target_os="linux")]
#[cfg(target_os="android")]
#[cfg(any(target_os="linux", target_os = "android"))]
fn create_scaled_font(template: &Arc<FontTemplateData>, pt_size: Au) -> ScaledFont {
ScaledFont::new(SkiaBackend, FontData(&template.bytes), pt_size.to_subpx() as AzFloat)
}

View file

@ -4,13 +4,13 @@
#![feature(globs, macro_rules, phase, unsafe_destructor)]
#![deny(unused_imports, unused_variable)]
#![deny(unused_imports)]
#![deny(unused_variables)]
#![feature(phase)]
#[phase(plugin, link)]
extern crate log;
extern crate debug;
extern crate azure;
extern crate collections;
extern crate geom;
@ -38,8 +38,11 @@ extern crate url;
extern crate harfbuzz;
// Linux and Android-specific library dependencies
#[cfg(target_os="linux")] #[cfg(target_os="android")] extern crate fontconfig;
#[cfg(target_os="linux")] #[cfg(target_os="android")] extern crate freetype;
#[cfg(any(target_os="linux", target_os = "android"))]
extern crate fontconfig;
#[cfg(any(target_os="linux", target_os = "android"))]
extern crate freetype;
// Mac OS-specific library dependencies
#[cfg(target_os="macos")] extern crate core_foundation;

View file

@ -43,7 +43,7 @@ pub struct FontTable;
impl FontTableMethods for FontTable {
fn with_buffer(&self, _blk: |*const u8, uint|) {
fail!()
panic!()
}
}
@ -61,7 +61,7 @@ impl Drop for FontHandle {
assert!(self.face.is_not_null());
unsafe {
if !FT_Done_Face(self.face).succeeded() {
fail!("FT_Done_Face failed");
panic!("FT_Done_Face failed");
}
}
}
@ -139,15 +139,15 @@ impl FontHandleMethods for FontHandle {
if valid {
let weight =(*os2).usWeightClass;
match weight {
1 | 100..199 => font_weight::Weight100,
2 | 200..299 => font_weight::Weight200,
3 | 300..399 => font_weight::Weight300,
4 | 400..499 => font_weight::Weight400,
5 | 500..599 => font_weight::Weight500,
6 | 600..699 => font_weight::Weight600,
7 | 700..799 => font_weight::Weight700,
8 | 800..899 => font_weight::Weight800,
9 | 900..999 => font_weight::Weight900,
1 | 100...199 => font_weight::Weight100,
2 | 200...299 => font_weight::Weight200,
3 | 300...399 => font_weight::Weight300,
4 | 400...499 => font_weight::Weight400,
5 | 500...599 => font_weight::Weight500,
6 | 600...699 => font_weight::Weight600,
7 | 700...799 => font_weight::Weight700,
8 | 800...899 => font_weight::Weight800,
9 | 900...999 => font_weight::Weight900,
_ => default_weight
}
} else {
@ -190,7 +190,6 @@ impl FontHandleMethods for FontHandle {
let void_glyph = (*self.face).glyph;
let slot: FT_GlyphSlot = mem::transmute(void_glyph);
assert!(slot.is_not_null());
debug!("metrics: {:?}", (*slot).metrics);
let advance = (*slot).metrics.horiAdvance;
debug!("h_advance for {} is {}", glyph, advance);
let advance = advance as i32;
@ -255,7 +254,7 @@ impl FontHandleMethods for FontHandle {
line_gap: height,
};
debug!("Font metrics (@{:f} pt): {:?}", geometry::to_pt(em_size), metrics);
debug!("Font metrics (@{:f} pt): {}", geometry::to_pt(em_size), metrics);
return metrics;
}
@ -297,4 +296,3 @@ impl<'a> FontHandle {
return geometry::from_frac_px(value * x_scale);
}
}

View file

@ -70,7 +70,7 @@ impl FontContextHandle {
let mut ctx: FT_Library = ptr::null_mut();
let result = FT_New_Library(ptr as FT_Memory, &mut ctx);
if !result.succeeded() { fail!("Unable to initialize FreeType library"); }
if !result.succeeded() { panic!("Unable to initialize FreeType library"); }
FT_Add_Default_Modules(ctx);

View file

@ -75,13 +75,13 @@ pub fn get_variations_for_family(family_name: &str, callback: |String|) {
let file = if FcPatternGetString(*font, FC_FILE.as_ptr() as *mut i8, 0, &mut file) == FcResultMatch {
string::raw::from_buf(file as *const i8 as *const u8)
} else {
fail!();
panic!();
};
let mut index: libc::c_int = 0;
let index = if FcPatternGetInteger(*font, FC_INDEX.as_ptr() as *mut i8, 0, &mut index) == FcResultMatch {
index
} else {
fail!();
panic!();
};
debug!("variation file: {}", file);

View file

@ -178,7 +178,7 @@ impl FontHandleMethods for FontHandle {
average_advance: average_advance,
line_gap: Au::from_frac_px(line_gap),
};
debug!("Font metrics (@{:f} pt): {:?}", self.ctfont.pt_size() as f64, metrics);
debug!("Font metrics (@{:f} pt): {}", self.ctfont.pt_size() as f64, metrics);
return metrics;
}

View file

@ -2,15 +2,13 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#[cfg(target_os="linux")]
#[cfg(target_os="android")]
#[cfg(any(target_os="linux", target_os = "android"))]
pub use platform::freetype::{font, font_context, font_list, font_template};
#[cfg(target_os="macos")]
pub use platform::macos::{font, font_context, font_list, font_template};
#[cfg(target_os="linux")]
#[cfg(target_os="android")]
#[cfg(any(target_os="linux", target_os = "android"))]
pub mod freetype {
pub mod font;
pub mod font_context;

View file

@ -114,8 +114,8 @@ impl<'a> RenderContext<'a> {
let (pixel_width, pixels, source_format) = match image.pixels {
RGBA8(ref pixels) => (4, pixels.as_slice(), B8G8R8A8),
K8(ref pixels) => (1, pixels.as_slice(), A8),
RGB8(_) => fail!("RGB8 color type not supported"),
KA8(_) => fail!("KA8 color type not supported"),
RGB8(_) => panic!("RGB8 color type not supported"),
KA8(_) => panic!("KA8 color type not supported"),
};
let stride = image.width * pixel_width;
@ -366,7 +366,7 @@ impl<'a> RenderContext<'a> {
let is_groove = match style {
border_style::groove => true,
border_style::ridge => false,
_ => fail!("invalid border style")
_ => panic!("invalid border style")
};
let darker_color = self.scale_color(color, if is_groove { 1.0/3.0 } else { 2.0/3.0 });
let (outer_color, inner_color) = match (direction, is_groove) {
@ -388,7 +388,7 @@ impl<'a> RenderContext<'a> {
let is_inset = match style {
border_style::inset => true,
border_style::outset => false,
_ => fail!("invalid border style")
_ => panic!("invalid border style")
};
// original bounds as a Rect<f32>
let original_bounds = self.get_scaled_bounds(bounds, border, 0.0);

View file

@ -152,7 +152,7 @@ impl<C> RenderTask<C> where C: RenderListener + Send {
time_profiler_chan: TimeProfilerChan,
shutdown_chan: Sender<()>) {
let ConstellationChan(c) = constellation_chan.clone();
spawn_named_with_send_on_failure("RenderTask", task_state::Render, proc() {
spawn_named_with_send_on_failure("RenderTask", task_state::RENDER, proc() {
{
// Ensures that the render task and graphics context are destroyed before the
// shutdown message.
@ -237,7 +237,7 @@ impl<C> RenderTask<C> where C: RenderListener + Send {
if self.epoch == epoch {
self.render(&mut replies, buffer_requests, scale, layer_id);
} else {
debug!("renderer epoch mismatch: {:?} != {:?}", self.epoch, epoch);
debug!("renderer epoch mismatch: {} != {}", self.epoch, epoch);
}
}
@ -340,14 +340,14 @@ impl<C> RenderTask<C> where C: RenderListener + Send {
for (i, tile) in tiles.into_iter().enumerate() {
let thread_id = i % self.worker_threads.len();
let layer_buffer = self.find_or_create_layer_buffer_for_tile(&tile, scale);
self.worker_threads.get_mut(thread_id).paint_tile(tile,
layer_buffer,
render_layer.clone(),
scale);
self.worker_threads[thread_id].paint_tile(tile,
layer_buffer,
render_layer.clone(),
scale);
}
let new_buffers = Vec::from_fn(tile_count, |i| {
let thread_id = i % self.worker_threads.len();
self.worker_threads.get_mut(thread_id).get_painted_tile_buffer()
self.worker_threads[thread_id].get_painted_tile_buffer()
});
let layer_buffer_set = box LayerBufferSet {
@ -570,4 +570,3 @@ enum MsgToWorkerThread {
enum MsgFromWorkerThread {
PaintedTileMsgFromWorkerThread(Box<LayerBuffer>),
}

View file

@ -7,7 +7,7 @@ use servo_util::range;
use servo_util::range::{Range, RangeIndex, IntRangeIndex, EachIndex};
use servo_util::geometry::Au;
use std::cmp::{PartialOrd, PartialEq};
use std::cmp::PartialOrd;
use std::num::{NumCast, Zero};
use std::mem;
use std::u16;
@ -22,7 +22,7 @@ use geom::point::Point2D;
/// In the uncommon case (multiple glyphs per unicode character, large glyph index/advance, or
/// glyph offsets), we pack the glyph count into GlyphEntry, and store the other glyph information
/// in DetailedGlyphStore.
#[deriving(Clone)]
#[deriving(Clone, Show)]
struct GlyphEntry {
value: u32,
}
@ -251,7 +251,7 @@ impl GlyphEntry {
// Stores data for a detailed glyph, in the case that several glyphs
// correspond to one character, or the glyph's data couldn't be packed.
#[deriving(Clone)]
#[deriving(Clone, Show)]
struct DetailedGlyph {
id: GlyphId,
// glyph's advance, in the text's direction (RTL or RTL)
@ -270,7 +270,7 @@ impl DetailedGlyph {
}
}
#[deriving(PartialEq, Clone, Eq)]
#[deriving(PartialEq, Clone, Eq, Show)]
struct DetailedGlyphRecord {
// source string offset/GlyphEntry offset in the TextRun
entry_offset: CharIndex,
@ -319,7 +319,7 @@ impl<'a> DetailedGlyphStore {
detail_offset: self.detail_buffer.len() as int,
};
debug!("Adding entry[off={}] for detailed glyphs: {:?}", entry_offset, glyphs);
debug!("Adding entry[off={}] for detailed glyphs: {}", entry_offset, glyphs);
/* TODO: don't actually assert this until asserts are compiled
in/out based on severity, debug/release, etc. This assertion
@ -563,7 +563,7 @@ impl<'a> GlyphStore {
}
}.adapt_character_flags_of_entry(self.entry_buffer[i.to_uint()]);
*self.entry_buffer.get_mut(i.to_uint()) = entry;
self.entry_buffer[i.to_uint()] = entry;
}
pub fn add_glyphs_for_char_index(&mut self, i: CharIndex, data_for_glyphs: &[GlyphData]) {
@ -589,9 +589,9 @@ impl<'a> GlyphStore {
}
}.adapt_character_flags_of_entry(self.entry_buffer[i.to_uint()]);
debug!("Adding multiple glyphs[idx={}, count={}]: {:?}", i, glyph_count, entry);
debug!("Adding multiple glyphs[idx={}, count={}]: {}", i, glyph_count, entry);
*self.entry_buffer.get_mut(i.to_uint()) = entry;
self.entry_buffer[i.to_uint()] = entry;
}
// used when a character index has no associated glyph---for example, a ligature continuation.
@ -601,7 +601,7 @@ impl<'a> GlyphStore {
let entry = GlyphEntry::complex(cluster_start, ligature_start, 0);
debug!("adding spacer for chracter without associated glyph[idx={}]", i);
*self.entry_buffer.get_mut(i.to_uint()) = entry;
self.entry_buffer[i.to_uint()] = entry;
}
pub fn iter_glyphs_for_char_index(&'a self, i: CharIndex) -> GlyphIterator<'a> {
@ -611,10 +611,10 @@ impl<'a> GlyphStore {
#[inline]
pub fn iter_glyphs_for_char_range(&'a self, rang: &Range<CharIndex>) -> GlyphIterator<'a> {
if rang.begin() >= self.char_len() {
fail!("iter_glyphs_for_range: range.begin beyond length!");
panic!("iter_glyphs_for_range: range.begin beyond length!");
}
if rang.end() > self.char_len() {
fail!("iter_glyphs_for_range: range.end beyond length!");
panic!("iter_glyphs_for_range: range.end beyond length!");
}
GlyphIterator {
@ -666,25 +666,25 @@ impl<'a> GlyphStore {
pub fn set_char_is_space(&mut self, i: CharIndex) {
assert!(i < self.char_len());
let entry = self.entry_buffer[i.to_uint()];
*self.entry_buffer.get_mut(i.to_uint()) = entry.set_char_is_space();
self.entry_buffer[i.to_uint()] = entry.set_char_is_space();
}
pub fn set_char_is_tab(&mut self, i: CharIndex) {
assert!(i < self.char_len());
let entry = self.entry_buffer[i.to_uint()];
*self.entry_buffer.get_mut(i.to_uint()) = entry.set_char_is_tab();
self.entry_buffer[i.to_uint()] = entry.set_char_is_tab();
}
pub fn set_char_is_newline(&mut self, i: CharIndex) {
assert!(i < self.char_len());
let entry = self.entry_buffer[i.to_uint()];
*self.entry_buffer.get_mut(i.to_uint()) = entry.set_char_is_newline();
self.entry_buffer[i.to_uint()] = entry.set_char_is_newline();
}
pub fn set_can_break_before(&mut self, i: CharIndex, t: BreakType) {
assert!(i < self.char_len());
let entry = self.entry_buffer[i.to_uint()];
*self.entry_buffer.get_mut(i.to_uint()) = entry.set_can_break_before(t);
self.entry_buffer[i.to_uint()] = entry.set_can_break_before(t);
}
}

View file

@ -249,7 +249,7 @@ impl Shaper {
} else {
byte_to_glyph = Vec::from_elem(byte_max as uint, CONTINUATION_BYTE);
for (i, _) in text.char_indices() {
*byte_to_glyph.get_mut(i) = NO_GLYPH;
byte_to_glyph[i] = NO_GLYPH;
}
}
@ -259,7 +259,7 @@ impl Shaper {
let loc = glyph_data.byte_offset_of_glyph(i);
if loc < byte_max {
assert!(byte_to_glyph[loc as uint] != CONTINUATION_BYTE);
*byte_to_glyph.get_mut(loc as uint) = i as i32;
byte_to_glyph[loc as uint] = i as i32;
} else {
debug!("ERROR: tried to set out of range byte_to_glyph: idx={}, glyph idx={}",
loc,
@ -271,7 +271,7 @@ impl Shaper {
debug!("text: {:s}", text);
debug!("(char idx): char->(glyph index):");
for (i, ch) in text.char_indices() {
debug!("{}: {} --> {:d}", i, ch, *byte_to_glyph.get(i) as int);
debug!("{}: {} --> {:d}", i, ch, *byte_to_glyph.get(i).unwrap() as int);
}
// some helpers

View file

@ -238,9 +238,9 @@ impl<'a> TextRun {
}
pub fn min_width_for_range(&self, range: &Range<CharIndex>) -> Au {
debug!("iterating outer range {:?}", range);
debug!("iterating outer range {}", range);
self.iter_slices_for_range(range).fold(Au(0), |max_piece_width, (_, offset, slice_range)| {
debug!("iterated on {:?}[{:?}]", offset, slice_range);
debug!("iterated on {}[{}]", offset, slice_range);
Au::max(max_piece_width, self.advance_for_range(&slice_range))
})
}

View file

@ -48,7 +48,7 @@ pub fn transform_text(text: &str,
if ch != '\n' {
new_line_index = new_line_index + CharIndex(1);
}
output_text.push_char(ch);
output_text.push(ch);
}
}
text.len() > 0 && is_in_whitespace(text.char_at_reverse(0), mode)
@ -67,14 +67,14 @@ pub fn transform_text(text: &str,
// TODO: record skipped char
} else {
// TODO: record kept char
output_text.push_char(ch);
output_text.push(ch);
}
} else { /* next_in_whitespace; possibly add a space char */
if in_whitespace {
// TODO: record skipped char
} else {
// TODO: record kept char
output_text.push_char(' ');
output_text.push(' ');
}
}
// save whitespace context for next char