From f27dda86ff0390585cd8bc93d332ff6f2aa08b3a Mon Sep 17 00:00:00 2001 From: Alexander Krotov Date: Wed, 24 Jul 2019 02:02:55 +0300 Subject: [PATCH] Move dc_array_search_id into dc_array_t implementation --- src/dc_array.rs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/dc_array.rs b/src/dc_array.rs index 7f407a709..b438ed679 100644 --- a/src/dc_array.rs +++ b/src/dc_array.rs @@ -71,6 +71,15 @@ impl dc_array_t { } } } + + pub fn search_id(&self, needle: uintptr_t) -> Option { + for (i, &u) in self.array.iter().enumerate() { + if u == needle { + return Some(i); + } + } + None + } } /** @@ -258,15 +267,14 @@ pub unsafe fn dc_array_search_id( if array.is_null() { return false; } - for (i, &u) in (*array).array.iter().enumerate() { - if u == needle as size_t { - if !ret_index.is_null() { - *ret_index = i - } - return true; + if let Some(i) = (*array).search_id(needle as uintptr_t) { + if !ret_index.is_null() { + *ret_index = i } + true + } else { + false } - false } pub unsafe fn dc_array_get_raw(array: *const dc_array_t) -> *const uintptr_t {