Remove dc_arr_to_string function that was used only once

This commit is contained in:
Alexander Krotov
2019-07-23 02:56:50 +03:00
committed by holger krekel
parent afcf48f833
commit 648d3d78aa
3 changed files with 8 additions and 40 deletions

View File

@@ -379,28 +379,6 @@ pub unsafe fn dc_array_get_string(
to_cstring(res)
}
/// return comma-separated value-string from integer array
pub unsafe fn dc_arr_to_string(arr: *const uint32_t, cnt: libc::c_int) -> *mut libc::c_char {
if arr.is_null() || cnt == 0 {
return dc_strdup(b"\x00" as *const u8 as *const libc::c_char);
}
let slice = std::slice::from_raw_parts(arr, cnt as usize);
let res = slice.iter().enumerate().fold(
String::with_capacity(2 * cnt as usize),
|mut res, (i, n)| {
if i == 0 {
res += &n.to_string();
} else {
res += ",";
res += &n.to_string();
}
res
},
);
to_cstring(res)
}
#[cfg(test)]
mod tests {
use super::*;

View File

@@ -1999,21 +1999,26 @@ pub unsafe fn dc_forward_msgs(
let chat = dc_chat_new(context);
let contact = dc_contact_new(context);
let created_db_entries = carray_new(16);
let mut idsstr = 0 as *mut libc::c_char;
let mut curr_timestamp: i64;
let original_param: *mut dc_param_t = dc_param_new();
dc_unarchive_chat(context, chat_id);
if dc_chat_load_from_db(chat, chat_id) {
curr_timestamp = dc_create_smeared_timestamps(context, msg_cnt);
idsstr = dc_arr_to_string(msg_ids, msg_cnt);
let idsstr = std::slice::from_raw_parts(msg_ids, msg_cnt as usize)
.iter()
.enumerate()
.fold(
String::with_capacity(2 * msg_cnt as usize),
|acc, (i, n)| (if i == 0 { acc } else { acc + "," }) + &n.to_string(),
);
let ids = context
.sql
.query_map(
format!(
"SELECT id FROM msgs WHERE id IN({}) ORDER BY timestamp,id",
as_str(idsstr)
idsstr
),
params![],
|row| row.get::<_, i32>(0),
@@ -2100,7 +2105,6 @@ pub unsafe fn dc_forward_msgs(
dc_contact_unref(contact);
dc_msg_unref(msg);
dc_chat_unref(chat);
free(idsstr as *mut libc::c_void);
dc_param_unref(original_param);
}

View File

@@ -1021,17 +1021,3 @@ fn test_wrong_db() {
assert_eq!(res, 0);
}
}
#[test]
fn test_arr_to_string() {
let arr2: [uint32_t; 4] = [
0i32 as uint32_t,
12i32 as uint32_t,
133i32 as uint32_t,
1999999i32 as uint32_t,
];
let str_0 = unsafe { dc_arr_to_string(arr2.as_ptr(), 4i32) };
assert_eq!(to_string(str_0), "0,12,133,1999999");
unsafe { free(str_0 as *mut _) };
}