Optimize returns in file_asset_io.rs and entities.rs (#728)

Optimize returns in file_asset_io.rs and entities.rs
This commit is contained in:
Freya 2020-10-28 18:59:45 -05:00 committed by GitHub
parent 8c053e7c67
commit 040b8f72b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 9 deletions

View File

@ -50,10 +50,10 @@ impl AssetIo for FileAssetIo {
file.read_to_end(&mut bytes)?;
}
Err(e) => {
if e.kind() == std::io::ErrorKind::NotFound {
return Err(AssetIoError::NotFound(path.to_owned()));
return if e.kind() == std::io::ErrorKind::NotFound {
Err(AssetIoError::NotFound(path.to_owned()))
} else {
return Err(e.into());
Err(e.into())
}
}
}

View File

@ -83,18 +83,18 @@ impl Entities {
pub fn reserve_entity(&self) -> Entity {
loop {
let index = self.free_cursor.load(Ordering::Relaxed);
match index.checked_sub(1) {
return match index.checked_sub(1) {
// The freelist is empty, so increment `pending` to arrange for a new entity with a
// predictable ID to be allocated on the next `flush` call
None => {
let n = self.pending.fetch_add(1, Ordering::Relaxed);
return Entity {
Entity {
generation: 0,
id: u32::try_from(self.meta.len())
.ok()
.and_then(|x| x.checked_add(n))
.expect("too many entities"),
};
}
}
// The freelist has entities in it, so move the last entry to the reserved list, to
// be consumed by the caller as part of a higher-level flush.
@ -111,12 +111,12 @@ impl Entities {
let id = self.free[next as usize];
let reservation = self.reserved_cursor.fetch_add(1, Ordering::Relaxed);
self.reserved[reservation as usize].store(id, Ordering::Relaxed);
return Entity {
Entity {
generation: self.meta[id as usize].generation,
id,
};
}
}
}
};
}
}