[fractal/fractal-next] room_list: Use get index instead of using nth
- From: Julian Sparber <jsparber src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal/fractal-next] room_list: Use get index instead of using nth
- Date: Thu, 16 Sep 2021 12:58:15 +0000 (UTC)
commit 0142c21c2bd331b29a906493fa092b3fed5d9c73
Author: SeaDve <davecruz48 gmail com>
Date: Thu Sep 16 20:32:11 2021 +0800
room_list: Use get index instead of using nth
It is a bit faster on larger collections since nth calls next on every item until
it becomes None, while get_index is similar to a Vec's get method
src/session/room_list.rs | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
---
diff --git a/src/session/room_list.rs b/src/session/room_list.rs
index 41bfe1e1..5ba9c580 100644
--- a/src/session/room_list.rs
+++ b/src/session/room_list.rs
@@ -93,9 +93,8 @@ mod imp {
fn item(&self, _list_model: &Self::Type, position: u32) -> Option<glib::Object> {
self.list
.borrow()
- .values()
- .nth(position as usize)
- .map(glib::object::Cast::upcast_ref::<glib::Object>)
+ .get_index(position as usize)
+ .map(|(_, v)| v.upcast_ref::<glib::Object>())
.cloned()
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]