diff options
| author | Zeyla Hellyer <[email protected]> | 2017-10-10 20:08:11 -0700 |
|---|---|---|
| committer | Zeyla Hellyer <[email protected]> | 2017-10-10 20:08:11 -0700 |
| commit | 93e0a4215c915b98cf433ac6d0bcfbc60f0168ec (patch) | |
| tree | 727111506d1f89cd8a511b8b79c102131222421f /src/utils | |
| parent | Resume on resumable session invalidations (diff) | |
| download | serenity-93e0a4215c915b98cf433ac6d0bcfbc60f0168ec.tar.xz serenity-93e0a4215c915b98cf433ac6d0bcfbc60f0168ec.zip | |
Switch to parking_lot::{Mutex, RwLock}
Switch to the `parking_lot` crate's implementations of
`std::sync::Mutex` and `std::sync::RwLock`, which are more efficient.
A writeup on why `parking_lot` is more efficient can be read here:
<https://github.com/Amanieu/parking_lot>
Upgrade path:
Modify `mutex.lock().unwrap()` usage to `mutex.lock()` (not needing to
unwrap or handle a result), and
`rwlock.read().unwrap()`/`rwlock.write().unwrap()` usage to
`rwlock.read()` and `rwlock.write()`.
For example, modify:
```rust
use serenity::CACHE;
println!("{}", CACHE.read().unwrap().user.id);
```
to:
```rust
use serenity::CACHE;
println!("{}", CACHE.read().user.id);
```
Diffstat (limited to 'src/utils')
| -rw-r--r-- | src/utils/mod.rs | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 4b36b73..c6d27c3 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -455,7 +455,7 @@ pub fn shard_id(guild_id: u64, shard_count: u64) -> u64 { (guild_id >> 22) % sha #[cfg(feature = "cache")] pub fn with_cache<T, F>(f: F) -> T where F: Fn(&Cache) -> T { - let cache = CACHE.read().unwrap(); + let cache = CACHE.read(); f(&cache) } @@ -476,6 +476,6 @@ pub fn with_cache<T, F>(f: F) -> T #[cfg(feature = "cache")] pub fn with_cache_mut<T, F>(mut f: F) -> T where F: FnMut(&mut Cache) -> T { - let mut cache = CACHE.write().unwrap(); + let mut cache = CACHE.write(); f(&mut cache) } |