Skip to content

Commit

Permalink
removed VecExtensions because its functionality is already in vec
Browse files Browse the repository at this point in the history
  • Loading branch information
mrDIMAS committed Aug 11, 2023
1 parent 27864b4 commit 85ad81d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 47 deletions.
40 changes: 0 additions & 40 deletions fyrox-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,46 +287,6 @@ where
}
}

pub trait VecExtensions<T> {
/// Retains only the elements specified by the predicate.
///
/// In other words, remove all elements `e` such that `f(&mut e)` returns `false`.
/// This method operates in place, visiting each element exactly once in the
/// original order, and preserves the order of the retained elements.
///
/// # Notes
///
/// This method is the copy of `retain` method of Vec, but with ability to
/// modify each element.
fn retain_mut_ext<F>(&mut self, f: F)
where
F: FnMut(&mut T) -> bool;
}

impl<T> VecExtensions<T> for Vec<T> {
fn retain_mut_ext<F>(&mut self, mut f: F)
where
F: FnMut(&mut T) -> bool,
{
let len = self.len();
let mut del = 0;
{
let v = &mut **self;

for i in 0..len {
if !f(&mut v[i]) {
del += 1;
} else if del > 0 {
v.swap(i - del, i);
}
}
}
if del > 0 {
self.truncate(len - del);
}
}
}

#[inline]
pub fn hash_combine(lhs: u64, rhs: u64) -> u64 {
lhs ^ (rhs
Expand Down
4 changes: 2 additions & 2 deletions fyrox-resource/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use fyrox_core::{
parking_lot::{Mutex, MutexGuard},
uuid::Uuid,
watcher::FileSystemWatcher,
TypeUuidProvider, VecExtensions,
TypeUuidProvider,
};
use std::path::PathBuf;
use std::{
Expand Down Expand Up @@ -255,7 +255,7 @@ impl ResourceManagerState {
/// Normally, this is called from `Engine::update()`.
/// You should only call this manually if you don't use that method.
pub fn update(&mut self, dt: f32) {
self.resources.retain_mut_ext(|resource| {
self.resources.retain_mut(|resource| {
// One usage means that the resource has single owner, and that owner
// is this container. Such resources have limited life time, if the time
// runs out before it gets shared again, the resource will be deleted.
Expand Down
7 changes: 2 additions & 5 deletions src/scene/graph/event.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
//! Graph event broadcaster allows you to receive graph events such as node deletion or addition.
//! Check [GraphEventBroadcaster::subscribe] for examples.

use crate::{
core::{pool::Handle, VecExtensions},
scene::node::Node,
};
use crate::{core::pool::Handle, scene::node::Node};
use std::{
fmt::{Debug, Formatter},
sync::mpsc::Sender,
Expand Down Expand Up @@ -69,6 +66,6 @@ impl GraphEventBroadcaster {

pub(crate) fn broadcast(&mut self, event: GraphEvent) {
self.senders
.retain_mut_ext(|sender| sender.send(event.clone()).is_ok());
.retain_mut(|sender| sender.send(event.clone()).is_ok());
}
}

0 comments on commit 85ad81d

Please sign in to comment.