Remove @self hack from FontCache

This commit is contained in:
Brian Anderson 2012-10-12 12:43:08 -07:00
parent c3170ac865
commit 03732b0cce

View file

@ -2,10 +2,6 @@ export FontCache, native;
use font::{Font, test_font_bin}; use font::{Font, test_font_bin};
struct FontCache { struct FontCache {
// FIXME: This is a hack to hold onto a boxed reference to
// the self pointer until explicit self types work on methods.
// This is a huge space leak.
mut at_self: Option<@FontCache>,
native_lib: native::NativeFontCache, native_lib: native::NativeFontCache,
drop { drop {
@ -14,27 +10,22 @@ struct FontCache {
} }
impl FontCache { impl FontCache {
fn get_font() -> @Font { fn get_font(@self) -> @Font {
assert self.at_self.is_some(); match create_font(self, &self.native_lib) {
match create_font(self.at_self.get(), &self.native_lib) {
Ok(font) => font, Ok(font) => font,
Err(*) => /* FIXME */ fail Err(*) => /* FIXME */ fail
} }
} }
fn get_test_font() -> @Font { fn get_test_font(@self) -> @Font {
self.get_font() self.get_font()
} }
} }
fn FontCache() -> @FontCache { fn FontCache() -> @FontCache {
let lib = @FontCache { @FontCache {
mut at_self: None,
native_lib: native::create_native_lib() native_lib: native::create_native_lib()
}; }
lib.at_self = Some(lib);
return lib;
} }
fn create_font(lib: @FontCache, native_lib: &native::NativeFontCache) -> Result<@Font, ()> { fn create_font(lib: @FontCache, native_lib: &native::NativeFontCache) -> Result<@Font, ()> {