Skip to content

Commit

Permalink
Simplify get_many_mut by using commutativity of equality.
Browse files Browse the repository at this point in the history
  • Loading branch information
adamreichold committed Jan 28, 2024
1 parent 9686da3 commit dffe671
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "rs-ecs"
description = "reasonably simple entity component system"
version = "0.7.6"
version = "0.7.7"
edition = "2018"
rust-version = "1.51"
authors = ["Adam Reichold <adam.reichold@t-online.de>"]
Expand Down
12 changes: 5 additions & 7 deletions src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,17 +525,15 @@ where

let ptr = val.as_mut_ptr() as *mut Option<<S::Fetch as Fetch>::Item>;

for idx1 in 0..N {
for idx2 in 0..N {
if idx1 != idx2 {
assert_ne!(ent[idx1], ent[idx2], "Duplicate entity");
}
for idx in 0..N {
for idx1 in (idx + 1)..N {
assert_ne!(ent[idx], ent[idx1], "Duplicate entity");
}

unsafe {
let val = self.get_unchecked(ent[idx1]);
let val = self.get_unchecked(ent[idx]);

ptr.add(idx1).write(val);
ptr.add(idx).write(val);
}
}

Expand Down

0 comments on commit dffe671

Please sign in to comment.