diff --git a/src/dc_array.rs b/src/dc_array.rs index 7bff7823f..a378e4740 100644 --- a/src/dc_array.rs +++ b/src/dc_array.rs @@ -19,6 +19,14 @@ impl dc_array_t { } } + /// Constructs a new, empty `dc_array_t` holding locations with specified `capacity`. + pub fn new_locations(capacity: usize) -> Self { + dc_array_t { + type_0: DC_ARRAY_LOCATIONS, + array: Vec::with_capacity(capacity), + } + } + pub fn as_ptr(self) -> *mut Self { Box::into_raw(Box::new(self)) } @@ -255,10 +263,8 @@ pub fn dc_array_new(initsize: size_t) -> *mut dc_array_t { dc_array_t::new(initsize).as_ptr() } -pub fn dc_array_new_typed(type_0: libc::c_int, initsize: size_t) -> *mut dc_array_t { - let mut array = dc_array_t::new(initsize); - array.type_0 = type_0; - array.as_ptr() +pub fn dc_array_new_locations(initsize: size_t) -> *mut dc_array_t { + dc_array_t::new_locations(initsize).as_ptr() } pub unsafe fn dc_array_empty(array: *mut dc_array_t) { diff --git a/src/dc_location.rs b/src/dc_location.rs index de15713e7..b529ad123 100644 --- a/src/dc_location.rs +++ b/src/dc_location.rs @@ -247,7 +247,7 @@ pub fn dc_get_locations( Ok(loc) }, |locations| { - let ret = dc_array_new_typed(1, 500); + let ret = dc_array_new_locations(500); for location in locations { unsafe { @@ -501,7 +501,7 @@ pub unsafe fn dc_kml_parse( } else { content_nullterminated = dc_null_terminate(content, content_bytes as libc::c_int); if !content_nullterminated.is_null() { - kml.locations = dc_array_new_typed(1, 100 as size_t); + kml.locations = dc_array_new_locations(100); dc_saxparser_init( &mut saxparser, &mut kml as *mut dc_kml_t as *mut libc::c_void,