Skip to content

Commit

Permalink
clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Oct 4, 2024
1 parent 3dccf44 commit bfbb7eb
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 33 deletions.
2 changes: 1 addition & 1 deletion turbopack/crates/turbo-tasks-backend/src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ impl TurboTasksBackendInner {

let mut new_items = false;

fn shards_empty<T>(shards: &Vec<ChunkedVec<T>>) -> bool {
fn shards_empty<T>(shards: &[ChunkedVec<T>]) -> bool {
shards.iter().all(|shard| shard.is_empty())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,11 @@ impl<'a> ExecuteContext<'a> {
category: TaskDataCategory,
) -> Vec<CachedDataItem> {
// Safety: `transaction` is a valid transaction from `self.backend.backing_storage`.
let items = unsafe {
unsafe {
self.backend
.backing_storage
.lookup_data(self.transaction(), task_id, category)
};
items
}
}

pub fn is_once_task(&self, task_id: TaskId) -> bool {
Expand Down Expand Up @@ -358,8 +357,7 @@ impl<'a> TaskGuard<'a> {
task.update(key, |old| {
let old_value_when_persistent = old
.as_ref()
.map(|old| old.is_persistent().then(|| old.clone()))
.flatten();
.and_then(|old| old.is_persistent().then(|| old.clone()));
let new = update(old);
let new_persistent = new.as_ref().map(|new| new.is_persistent()).unwrap_or(false);

Expand Down
34 changes: 11 additions & 23 deletions turbopack/crates/turbo-tasks-backend/src/lmdb_backing_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl LmdbBackingStorage {
) -> Result<T> {
if let Some(tx) = tx {
let tx = self.to_tx(tx);
f(&*tx)
f(&tx)
} else {
let tx = self.env.begin_ro_txn()?;
let r = f(&tx)?;
Expand Down Expand Up @@ -325,7 +325,7 @@ impl BackingStorage for LmdbBackingStorage {
task_type: &CachedTaskType,
) -> Result<Option<TaskId>> {
let task_type = pot::to_vec(task_type)?;
let bytes = match extended_key::get(&tx, this.forward_task_cache_db, &task_type) {
let bytes = match extended_key::get(tx, this.forward_task_cache_db, &task_type) {
Ok(result) => result,
Err(err) => {
if err == lmdb::Error::NotFound {
Expand Down Expand Up @@ -406,26 +406,19 @@ impl BackingStorage for LmdbBackingStorage {
}
}

fn organize_task_data(
updates: Vec<ChunkedVec<CachedDataUpdate>>,
) -> Vec<
HashMap<
TaskId,
HashMap<CachedDataItemKey, (Option<CachedDataItemValue>, Option<CachedDataItemValue>)>,
>,
> {
type OrganizedTaskData = HashMap<
TaskId,
HashMap<CachedDataItemKey, (Option<CachedDataItemValue>, Option<CachedDataItemValue>)>,
>;
type ShardedOrganizedTaskData = Vec<OrganizedTaskData>;

fn organize_task_data(updates: Vec<ChunkedVec<CachedDataUpdate>>) -> ShardedOrganizedTaskData {
let span = Span::current();
updates
.into_par_iter()
.map(|updates| {
let _span = span.clone().entered();
let mut task_updates: HashMap<
TaskId,
HashMap<
CachedDataItemKey,
(Option<CachedDataItemValue>, Option<CachedDataItemValue>),
>,
> = HashMap::new();
let mut task_updates: OrganizedTaskData = HashMap::new();
for CachedDataUpdate {
task,
key,
Expand Down Expand Up @@ -455,12 +448,7 @@ fn organize_task_data(
fn restore_task_data(
this: &LmdbBackingStorage,
db: Database,
task_updates: Vec<
HashMap<
TaskId,
HashMap<CachedDataItemKey, (Option<CachedDataItemValue>, Option<CachedDataItemValue>)>,
>,
>,
task_updates: ShardedOrganizedTaskData,
) -> Result<Vec<(TaskId, Vec<CachedDataItem>)>> {
let mut result = Vec::with_capacity(task_updates.iter().map(|m| m.len()).sum());

Expand Down
7 changes: 3 additions & 4 deletions turbopack/crates/turbo-tasks-backend/src/utils/sharded.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::hash::{BuildHasher, BuildHasherDefault, Hash, Hasher};
use std::hash::{BuildHasher, BuildHasherDefault, Hash};

use parking_lot::{Mutex, MutexGuard};
use rustc_hash::FxHasher;
Expand Down Expand Up @@ -33,9 +33,8 @@ impl<T, H> Sharded<T, H> {
K: Hash,
H: BuildHasher,
{
let mut h = self.hasher.build_hasher();
key.hash(&mut h);
let shard = h.finish() as u16 & self.bitmask;
let hash = self.hasher.hash_one(key);
let shard = hash as u16 & self.bitmask;
self.data[shard as usize].lock()
}

Expand Down

0 comments on commit bfbb7eb

Please sign in to comment.