Skip to content

Commit

Permalink
Appease the new borrow checker.
Browse files Browse the repository at this point in the history
  • Loading branch information
metajack committed May 10, 2013
1 parent 3c29167 commit 5324cab
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 55 deletions.
2 changes: 1 addition & 1 deletion src/servo-gfx/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ pub impl Font {
advance += glyph.advance();
}
let bounds = Rect(Point2D(Au(0), -self.metrics.ascent),
Size2D(advance, self.metrics.ascent + self.metrics.descent));
Size2D(advance, self.metrics.ascent + self.metrics.descent));

// TODO(Issue #125): support loose and tight bounding boxes; using the
// ascent+descent and advance is sometimes too generous and
Expand Down
5 changes: 2 additions & 3 deletions src/servo-gfx/font_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,9 @@ impl FontFamily {
}

fn load_family_variations(@mut self, list: &FontListHandle) {
let this : &mut FontFamily = self; // FIXME: borrow checker workaround
if this.entries.len() > 0 { return; }
if self.entries.len() > 0 { return; }
list.load_variations_for_family(self);
assert!(this.entries.len() > 0);
assert!(self.entries.len() > 0);
}

pub fn find_font_for_style(@mut self, list: &FontListHandle, style: &SpecifiedFontStyle)
Expand Down
16 changes: 7 additions & 9 deletions src/servo-gfx/platform/macos/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use geometry::Au;
use platform::macos::font_context::FontContextHandle;
use text::glyph::GlyphIndex;

use core_foundation::base::{CFIndex, CFWrapper};
use core_foundation::base::CFIndex;
use core_foundation::data::CFData;
use core_foundation::string::UniChar;
use core_graphics::data_provider::CGDataProvider;
Expand Down Expand Up @@ -106,7 +106,7 @@ impl FontHandleMethods for FontHandle {

fn boldness(&self) -> CSSFontWeight {
// -1.0 to 1.0
let normalized = unsafe { self.ctfont.all_traits().normalized_weight() };
let normalized = self.ctfont.all_traits().normalized_weight();
// 0.0 to 9.0
let normalized = (normalized + 1.0) / 2.0 * 9.0;
if normalized < 1.0 { return FontWeight100; }
Expand Down Expand Up @@ -146,13 +146,11 @@ impl FontHandleMethods for FontHandle {

fn glyph_h_advance(&self, glyph: GlyphIndex) -> Option<FractionalPixel> {
let glyphs = [glyph as CGGlyph];
unsafe {
let advance = self.ctfont.get_advances_for_glyphs(kCTFontDefaultOrientation,
&glyphs[0],
ptr::null(),
1);
return Some(advance as FractionalPixel);
}
let advance = self.ctfont.get_advances_for_glyphs(kCTFontDefaultOrientation,
&glyphs[0],
ptr::null(),
1);
Some(advance as FractionalPixel)
}

fn get_metrics(&self) -> FontMetrics {
Expand Down
6 changes: 2 additions & 4 deletions src/servo-gfx/platform/macos/font_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,9 @@ pub impl FontListHandle {
}

fn load_variations_for_family(&self, family: @mut FontFamily) {
let fam: &mut FontFamily = family; // FIXME: borrow checker workaround
let family_name = &fam.family_name;
debug!("Looking for faces of family: %s", *family_name);
debug!("Looking for faces of family: %s", family.family_name);

let family_collection = core_text::font_collection::create_for_family(*family_name);
let family_collection = core_text::font_collection::create_for_family(family.family_name);
for family_collection.get_descriptors().each |descref: &CTFontDescriptorRef| {
let desc = CFWrapper::wrap_shared(*descref);
let font = core_text::font::new_from_descriptor(&desc, 0.0);
Expand Down
31 changes: 11 additions & 20 deletions src/servo-net/image_cache_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,20 +373,13 @@ impl ImageCache {
}
priv fn purge_waiters(&self, url: Url, f: &fn() -> ImageResponseMsg) {
match self.wait_map.find(&url) {
Some(waiters) => {
let waiters = *waiters;
let mut new_waiters = ~[];
new_waiters <-> *waiters;
for new_waiters.each |response| {
response.send(f());
match self.wait_map.pop(&url) {
Some(waiters) => {
for waiters.each |response| {
response.send(f());
}
}
*waiters <-> new_waiters;
self.wait_map.remove(&url);
}
None => ()
None => ()
}
}
Expand All @@ -410,13 +403,11 @@ impl ImageCache {
Prefetching(DoDecode) | Decoding => {
// We don't have this image yet
match self.wait_map.find(&url) {
Some(waiters) => {
vec::push(*waiters, response);
}
None => {
self.wait_map.insert(url, @mut ~[response]);
}
if self.wait_map.contains_key(&url) {
let waiters = self.wait_map.find_mut(&url).unwrap();
waiters.push(response);
} else {
self.wait_map.insert(url, @mut ~[response]);
}
}
Expand Down
29 changes: 11 additions & 18 deletions src/servo-net/local_image_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,9 @@ pub impl LocalImageCache {

match state.last_response {
ImageReady(ref image) => {
// FIXME: appease borrowck
unsafe {
let (port, chan) = comm::stream();
chan.send(ImageReady(clone_arc(image)));
return port;
}
let (port, chan) = comm::stream();
chan.send(ImageReady(clone_arc(image)));
return port;
}
ImageNotReady => {
if last_round == self.round_number {
Expand Down Expand Up @@ -138,18 +135,14 @@ pub impl LocalImageCache {
}

priv fn get_state(&self, url: &Url) -> @mut ImageState {
match self.state_map.find(url) {
Some(state) => *state,
None => {
let new_state = @mut ImageState {
prefetched: false,
decoded: false,
last_request_round: 0,
last_response: ImageNotReady
};
self.state_map.insert(copy *url, new_state);
self.get_state(url)
}
*do self.state_map.find_or_insert_with(url.clone()) |_| {
let new_state = @mut ImageState {
prefetched: false,
decoded: false,
last_request_round: 0,
last_response: ImageNotReady
};
new_state
}
}
}
Expand Down

0 comments on commit 5324cab

Please sign in to comment.