diff options
author | Matt Brubeck <mbrubeck@limpet.net> | 2016-05-18 10:46:37 -0700 |
---|---|---|
committer | Matt Brubeck <mbrubeck@limpet.net> | 2016-05-19 09:44:56 -0700 |
commit | 1eab6fbb2e71e8daeece6e29308f3be2b3c7c5a1 (patch) | |
tree | 39f97503033e4df0f2a3fb73d5396ed0ecee1384 | |
parent | 2d5dc8fa6db4d714c2018d78f502b3298a32cfaf (diff) | |
download | servo-1eab6fbb2e71e8daeece6e29308f3be2b3c7c5a1.tar.gz servo-1eab6fbb2e71e8daeece6e29308f3be2b3c7c5a1.zip |
Simplify FontTableMethods::with_buffer
-rw-r--r-- | components/gfx/font.rs | 2 | ||||
-rw-r--r-- | components/gfx/platform/freetype/font.rs | 4 | ||||
-rw-r--r-- | components/gfx/platform/macos/font.rs | 4 | ||||
-rw-r--r-- | components/gfx/text/shaping/harfbuzz.rs | 10 |
4 files changed, 9 insertions, 11 deletions
diff --git a/components/gfx/font.rs b/components/gfx/font.rs index eda41c365fe..f97c5373190 100644 --- a/components/gfx/font.rs +++ b/components/gfx/font.rs @@ -68,7 +68,7 @@ impl FontTableTagConversions for FontTableTag { } pub trait FontTableMethods { - fn with_buffer<F>(&self, F) where F: FnOnce(*const u8, usize); + fn buffer(&self) -> &[u8]; } #[derive(Clone, Debug, Deserialize, Serialize)] diff --git a/components/gfx/platform/freetype/font.rs b/components/gfx/platform/freetype/font.rs index 282bd72944f..1ee14127f48 100644 --- a/components/gfx/platform/freetype/font.rs +++ b/components/gfx/platform/freetype/font.rs @@ -40,8 +40,8 @@ pub struct FontTable { } impl FontTableMethods for FontTable { - fn with_buffer<F>(&self, blk: F) where F: FnOnce(*const u8, usize) { - blk(self.buffer.as_ptr(), self.buffer.len()) + fn buffer(&self) -> &[u8] { + &self.buffer } } diff --git a/components/gfx/platform/macos/font.rs b/components/gfx/platform/macos/font.rs index c6be7c16d78..f1d418350d4 100644 --- a/components/gfx/platform/macos/font.rs +++ b/components/gfx/platform/macos/font.rs @@ -52,8 +52,8 @@ impl FontTable { } impl FontTableMethods for FontTable { - fn with_buffer<F>(&self, blk: F) where F: FnOnce(*const u8, usize) { - blk(self.data.bytes().as_ptr(), self.data.len() as usize); + fn buffer(&self) -> &[u8] { + self.data.bytes() } } diff --git a/components/gfx/text/shaping/harfbuzz.rs b/components/gfx/text/shaping/harfbuzz.rs index 964ba7cf396..ff765818069 100644 --- a/components/gfx/text/shaping/harfbuzz.rs +++ b/components/gfx/text/shaping/harfbuzz.rs @@ -529,15 +529,13 @@ extern fn font_table_func(_: *mut hb_face_t, // this raw pointer back to `destroy_blob_func` which will deallocate the Box. let font_table_ptr = Box::into_raw(font_table); - let mut blob: *mut hb_blob_t = ptr::null_mut(); - (*font_table_ptr).with_buffer(|buf: *const u8, len: usize| { - // HarfBuzz calls `destroy_blob_func` when the buffer is no longer needed. - blob = hb_blob_create(buf as *const c_char, - len as c_uint, + let buf = (*font_table_ptr).buffer(); + // HarfBuzz calls `destroy_blob_func` when the buffer is no longer needed. + let blob = hb_blob_create(buf.as_ptr() as *const c_char, + buf.len() as c_uint, HB_MEMORY_MODE_READONLY, font_table_ptr as *mut c_void, Some(destroy_blob_func)); - }); assert!(!blob.is_null()); blob |