From 6ae74b6673d70ed89276ee72a04a31f9bb0ca08b Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 8 Apr 2015 19:00:34 +0200 Subject: [PATCH] Pass the buffer to create_face_from_buffer. It's better to hold on to the abstraction as long as possible. --- components/gfx/platform/freetype/font.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/components/gfx/platform/freetype/font.rs b/components/gfx/platform/freetype/font.rs index 181c3569bab..60587acb297 100644 --- a/components/gfx/platform/freetype/font.rs +++ b/components/gfx/platform/freetype/font.rs @@ -76,8 +76,7 @@ impl FontHandleMethods for FontHandle { let ft_ctx: FT_Library = fctx.ctx.ctx; if ft_ctx.is_null() { return Err(()); } - let bytes = &template.bytes; - let face_result = create_face_from_buffer(ft_ctx, bytes.as_ptr(), bytes.len(), pt_size); + let face_result = create_face_from_buffer(ft_ctx, &template.bytes, pt_size); // TODO: this could be more simply written as result::chain // and moving buf into the struct ctor, but cant' move out of @@ -94,12 +93,12 @@ impl FontHandleMethods for FontHandle { Err(()) => Err(()) }; - fn create_face_from_buffer(lib: FT_Library, cbuf: *const u8, cbuflen: uint, pt_size: Option) + fn create_face_from_buffer(lib: FT_Library, buffer: &[u8], pt_size: Option) -> Result { unsafe { let mut face: FT_Face = ptr::null_mut(); let face_index = 0 as FT_Long; - let result = FT_New_Memory_Face(lib, cbuf, cbuflen as FT_Long, + let result = FT_New_Memory_Face(lib, buffer.as_ptr(), buffer.len() as FT_Long, face_index, &mut face); if !result.succeeded() || face.is_null() {