mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Auto merge of #6393 - Ms2ger:cef-string-multimap, r=jdm
<!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/6393) <!-- Reviewable:end -->
This commit is contained in:
commit
bb39e835f1
2 changed files with 18 additions and 33 deletions
|
@ -4,34 +4,25 @@
|
|||
|
||||
use eutil::slice_to_str;
|
||||
use libc::c_int;
|
||||
use std::boxed;
|
||||
use std::collections::BTreeMap;
|
||||
use std::mem;
|
||||
use std::string::String;
|
||||
use string::{cef_string_userfree_utf16_alloc, cef_string_userfree_utf16_free};
|
||||
use string::{cef_string_utf16_set};
|
||||
use types::{cef_string_multimap_t,cef_string_t};
|
||||
|
||||
fn string_multimap_to_treemap(smm: *mut cef_string_multimap_t) -> *mut BTreeMap<String, Vec<*mut cef_string_t>> {
|
||||
smm as *mut BTreeMap<String, Vec<*mut cef_string_t>>
|
||||
}
|
||||
|
||||
//cef_string_multimap
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn cef_string_multimap_alloc() -> *mut cef_string_multimap_t {
|
||||
unsafe {
|
||||
let smm: Box<BTreeMap<String, Vec<*mut cef_string_t>>> = box BTreeMap::new();
|
||||
mem::transmute(smm)
|
||||
}
|
||||
boxed::into_raw(box BTreeMap::new())
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn cef_string_multimap_size(smm: *mut cef_string_multimap_t) -> c_int {
|
||||
unsafe {
|
||||
if smm.is_null() { return 0; }
|
||||
let v = string_multimap_to_treemap(smm);
|
||||
// t1 : collections::btree::map::Values<'_, collections::string::String, collections::vec::Vec<*mut types::cef_string_utf16>>`
|
||||
let t1 = (*v).values();
|
||||
let t1 = (*smm).values();
|
||||
// t2 : collections::btree::map::BTreeMap<collections::string::String, collections::vec::Vec<*mut types::cef_string_utf16>>
|
||||
let t2 : usize = t1.map(|val| (*val).len()).sum();
|
||||
t2 as c_int
|
||||
|
@ -42,9 +33,8 @@ pub extern "C" fn cef_string_multimap_size(smm: *mut cef_string_multimap_t) -> c
|
|||
pub extern "C" fn cef_string_multimap_find_count(smm: *mut cef_string_multimap_t, key: *const cef_string_t) -> c_int {
|
||||
unsafe {
|
||||
if smm.is_null() { return 0; }
|
||||
let v = string_multimap_to_treemap(smm);
|
||||
slice_to_str((*key).str as *const u8, (*key).length as usize, |result| {
|
||||
match (*v).get(result) {
|
||||
match (*smm).get(result) {
|
||||
Some(s) => s.len() as c_int,
|
||||
None => 0
|
||||
}
|
||||
|
@ -56,13 +46,12 @@ pub extern "C" fn cef_string_multimap_find_count(smm: *mut cef_string_multimap_t
|
|||
pub extern "C" fn cef_string_multimap_append(smm: *mut cef_string_multimap_t, key: *const cef_string_t, value: *const cef_string_t) -> c_int {
|
||||
unsafe {
|
||||
if smm.is_null() { return 0; }
|
||||
let v = string_multimap_to_treemap(smm);
|
||||
slice_to_str((*key).str as *const u8, (*key).length as usize, |result| {
|
||||
let csv = cef_string_userfree_utf16_alloc();
|
||||
cef_string_utf16_set((*value).str as *const u16, (*value).length, csv, 1);
|
||||
match (*v).get_mut(result) {
|
||||
match (*smm).get_mut(result) {
|
||||
Some(vc) => (*vc).push(csv),
|
||||
None => { (*v).insert(result.to_owned(), vec!(csv)); }
|
||||
None => { (*smm).insert(result.to_owned(), vec!(csv)); }
|
||||
}
|
||||
1
|
||||
})
|
||||
|
@ -73,9 +62,8 @@ pub extern "C" fn cef_string_multimap_append(smm: *mut cef_string_multimap_t, ke
|
|||
pub extern "C" fn cef_string_multimap_enumerate(smm: *mut cef_string_multimap_t, key: *const cef_string_t, index: c_int, value: *mut cef_string_t) -> c_int {
|
||||
unsafe {
|
||||
if smm.is_null() { return 0; }
|
||||
let v = string_multimap_to_treemap(smm);
|
||||
slice_to_str((*key).str as *const u8, (*key).length as usize, |result| {
|
||||
match (*v).get(result) {
|
||||
match (*smm).get(result) {
|
||||
Some(s) => {
|
||||
if (*s).len() <= index as usize {
|
||||
return 0;
|
||||
|
@ -93,10 +81,9 @@ pub extern "C" fn cef_string_multimap_enumerate(smm: *mut cef_string_multimap_t,
|
|||
pub extern "C" fn cef_string_multimap_key(smm: *mut cef_string_multimap_t, index: c_int, value: *mut cef_string_t) -> c_int {
|
||||
unsafe {
|
||||
if index < 0 || smm.is_null() { return 0; }
|
||||
let v = string_multimap_to_treemap(smm);
|
||||
let mut rem = index as usize;
|
||||
|
||||
for (key, val) in (*v).iter() {
|
||||
for (key, val) in (*smm).iter() {
|
||||
if rem < (*val).len() {
|
||||
return cef_string_utf16_set((*key).as_bytes().as_ptr() as *const u16,
|
||||
(*key).len() as u64,
|
||||
|
@ -114,10 +101,9 @@ pub extern "C" fn cef_string_multimap_key(smm: *mut cef_string_multimap_t, index
|
|||
pub extern "C" fn cef_string_multimap_value(smm: *mut cef_string_multimap_t, index: c_int, value: *mut cef_string_t) -> c_int {
|
||||
unsafe {
|
||||
if index < 0 || smm.is_null() { return 0; }
|
||||
let v = string_multimap_to_treemap(smm);
|
||||
let mut rem = index as usize;
|
||||
|
||||
for val in (*v).values() {
|
||||
for val in (*smm).values() {
|
||||
if rem < (*val).len() {
|
||||
let cs = (*val)[rem as usize];
|
||||
return cef_string_utf16_set((*cs).str as *const u16, (*cs).length, value, 1);
|
||||
|
@ -133,15 +119,13 @@ pub extern "C" fn cef_string_multimap_value(smm: *mut cef_string_multimap_t, ind
|
|||
pub extern "C" fn cef_string_multimap_clear(smm: *mut cef_string_multimap_t) {
|
||||
unsafe {
|
||||
if smm.is_null() { return; }
|
||||
let v = string_multimap_to_treemap(smm);
|
||||
if (*v).len() == 0 { return; }
|
||||
for (_, val) in (*v).iter_mut() {
|
||||
while (*val).len() != 0 {
|
||||
let cs = (*val).pop();
|
||||
cef_string_userfree_utf16_free(cs.unwrap());
|
||||
if (*smm).len() == 0 { return; }
|
||||
for (_, val) in (*smm).iter_mut() {
|
||||
while let Some(cs) = (*val).pop() {
|
||||
cef_string_userfree_utf16_free(cs);
|
||||
}
|
||||
}
|
||||
(*v).clear();
|
||||
(*smm).clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -149,8 +133,7 @@ pub extern "C" fn cef_string_multimap_clear(smm: *mut cef_string_multimap_t) {
|
|||
pub extern "C" fn cef_string_multimap_free(smm: *mut cef_string_multimap_t) {
|
||||
unsafe {
|
||||
if smm.is_null() { return; }
|
||||
let v: Box<BTreeMap<String, Vec<*mut cef_string_t>>> = mem::transmute(smm);
|
||||
cef_string_multimap_clear(smm);
|
||||
drop(v);
|
||||
drop(Box::from_raw(smm));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,8 +13,10 @@ use net::net_error_list::NetError;
|
|||
|
||||
pub use self::cef_rect as cef_rect_t;
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
pub enum cef_string_map_t {}
|
||||
pub enum cef_string_multimap_t {}
|
||||
pub type cef_string_multimap_t = BTreeMap<String, Vec<*mut cef_string_t>>;
|
||||
pub type cef_string_list_t = Vec<String>;
|
||||
pub enum cef_text_input_context_t {}
|
||||
pub enum cef_event_handle_t {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue