mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
embedding: add string_map_to_vec() to reduce transmute calls
This commit is contained in:
parent
43cc865629
commit
69e8de33e8
1 changed files with 10 additions and 5 deletions
|
@ -8,6 +8,11 @@ use std::mem;
|
|||
use string::{cef_string_userfree_utf8_alloc,cef_string_userfree_utf8_free,cef_string_utf8_set};
|
||||
use types::{cef_string_list_t,cef_string_t};
|
||||
|
||||
|
||||
fn string_map_to_vec(lt: *mut cef_string_list_t) -> *mut Vec<*mut cef_string_t> {
|
||||
lt as *mut Vec<*mut cef_string_t>
|
||||
}
|
||||
|
||||
//cef_string_list
|
||||
|
||||
#[no_mangle]
|
||||
|
@ -22,7 +27,7 @@ pub extern "C" fn cef_string_list_alloc() -> *mut cef_string_list_t {
|
|||
pub extern "C" fn cef_string_list_size(lt: *mut cef_string_list_t) -> c_int {
|
||||
unsafe {
|
||||
if fptr_is_null(mem::transmute(lt)) { return 0; }
|
||||
let v: *mut Vec<*mut cef_string_t> = mem::transmute(lt);
|
||||
let v = string_map_to_vec(lt);
|
||||
(*v).len() as c_int
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +36,7 @@ pub extern "C" fn cef_string_list_size(lt: *mut cef_string_list_t) -> c_int {
|
|||
pub extern "C" fn cef_string_list_append(lt: *mut cef_string_list_t, value: *const cef_string_t) {
|
||||
unsafe {
|
||||
if fptr_is_null(mem::transmute(lt)) { return; }
|
||||
let v: *mut Vec<*mut cef_string_t> = mem::transmute(lt);
|
||||
let v = string_map_to_vec(lt);
|
||||
let cs = cef_string_userfree_utf8_alloc();
|
||||
cef_string_utf8_set(mem::transmute((*value).str), (*value).length, cs, 1);
|
||||
(*v).push(cs);
|
||||
|
@ -42,7 +47,7 @@ pub extern "C" fn cef_string_list_append(lt: *mut cef_string_list_t, value: *con
|
|||
pub extern "C" fn cef_string_list_value(lt: *mut cef_string_list_t, index: c_int, value: *mut cef_string_t) -> c_int {
|
||||
unsafe {
|
||||
if index < 0 || fptr_is_null(mem::transmute(lt)) { return 0; }
|
||||
let v: *mut Vec<*mut cef_string_t> = mem::transmute(lt);
|
||||
let v = string_map_to_vec(lt);
|
||||
if index as uint > (*v).len() - 1 { return 0; }
|
||||
let cs = (*v).get(index as uint);
|
||||
cef_string_utf8_set(mem::transmute((**cs).str), (**cs).length, value, 1)
|
||||
|
@ -53,7 +58,7 @@ pub extern "C" fn cef_string_list_value(lt: *mut cef_string_list_t, index: c_int
|
|||
pub extern "C" fn cef_string_list_clear(lt: *mut cef_string_list_t) {
|
||||
unsafe {
|
||||
if fptr_is_null(mem::transmute(lt)) { return; }
|
||||
let v: *mut Vec<*mut cef_string_t> = mem::transmute(lt);
|
||||
let v = string_map_to_vec(lt);
|
||||
if (*v).len() == 0 { return; }
|
||||
let mut cs;
|
||||
while (*v).len() != 0 {
|
||||
|
@ -77,7 +82,7 @@ pub extern "C" fn cef_string_list_free(lt: *mut cef_string_list_t) {
|
|||
pub extern "C" fn cef_string_list_copy(lt: *mut cef_string_list_t) -> *mut cef_string_list_t {
|
||||
unsafe {
|
||||
if fptr_is_null(mem::transmute(lt)) { return 0 as *mut cef_string_list_t; }
|
||||
let v: *mut Vec<*mut cef_string_t> = mem::transmute(lt);
|
||||
let v = string_map_to_vec(lt);
|
||||
let lt2 = cef_string_list_alloc();
|
||||
for cs in (*v).iter() {
|
||||
cef_string_list_append(lt2, mem::transmute((*cs)));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue