Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(turbo-tasks-backend): Use let instead of match for macro bindings #71756

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 51 additions & 61 deletions turbopack/crates/turbo-tasks-backend/src/backend/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,58 +469,51 @@ macro_rules! update {
#[allow(unused_imports)]
use $crate::backend::operation::TaskGuard;
#[allow(unused_mut)]
match $update {
mut update => $task.update(&$crate::data::CachedDataItemKey::$key $input, |old| {
update(old.and_then(|old| {
if let $crate::data::CachedDataItemValue::$key { value } = old {
Some(value)
} else {
None
}
}))
.map(|new| $crate::data::CachedDataItemValue::$key { value: new })
})
}
let mut update = $update;
$task.update(&$crate::data::CachedDataItemKey::$key $input, |old| {
update(old.and_then(|old| {
if let $crate::data::CachedDataItemValue::$key { value } = old {
Some(value)
} else {
None
}
}))
.map(|new| $crate::data::CachedDataItemValue::$key { value: new })
})
}};
($task:ident, $key:ident, $update:expr) => {
$crate::backend::storage::update!($task, $key {}, $update)
};
}

macro_rules! update_ucount_and_get {
($task:ident, $key:ident $input:tt, -$update:expr) => {
match $update {
update => {
let mut value = 0;
$crate::backend::storage::update!($task, $key $input, |old: Option<_>| {
if let Some(old) = old {
value = old - update;
(value != 0).then_some(value)
} else {
None
}
});
value
($task:ident, $key:ident $input:tt, -$update:expr) => {{
let update = $update;
let mut value = 0;
$crate::backend::storage::update!($task, $key $input, |old: Option<_>| {
if let Some(old) = old {
value = old - update;
(value != 0).then_some(value)
} else {
None
}
}
};
($task:ident, $key:ident $input:tt, $update:expr) => {
match $update {
update => {
let mut value = 0;
$crate::backend::storage::update!($task, $key $input, |old: Option<_>| {
if let Some(old) = old {
value = old + update;
(value != 0).then_some(value)
} else {
value = update;
(update != 0).then_some(update)
}
});
value
});
value
}};
($task:ident, $key:ident $input:tt, $update:expr) => {{
let update = $update;
let mut value = 0;
$crate::backend::storage::update!($task, $key $input, |old: Option<_>| {
if let Some(old) = old {
value = old + update;
(value != 0).then_some(value)
} else {
value = update;
(update != 0).then_some(update)
}
}
};
});
value
}};
($task:ident, $key:ident, -$update:expr) => {
$crate::backend::storage::update_ucount_and_get!($task, $key {}, -$update)
};
Expand All @@ -530,25 +523,22 @@ macro_rules! update_ucount_and_get {
}

macro_rules! update_count {
($task:ident, $key:ident $input:tt, -$update:expr) => {
match $update {
update => {
let mut state_change = false;
$crate::backend::storage::update!($task, $key $input, |old: Option<_>| {
#[allow(unused_comparisons, reason = "type of update might be unsigned, where update < 0 is always false")]
if let Some(old) = old {
let new = old - update;
state_change = old <= 0 && new > 0 || old > 0 && new <= 0;
(new != 0).then_some(new)
} else {
state_change = update < 0;
(update != 0).then_some(-update)
}
});
state_change
($task:ident, $key:ident $input:tt, -$update:expr) => {{
let update = $update;
let mut state_change = false;
$crate::backend::storage::update!($task, $key $input, |old: Option<_>| {
#[allow(unused_comparisons, reason = "type of update might be unsigned, where update < 0 is always false")]
if let Some(old) = old {
let new = old - update;
state_change = old <= 0 && new > 0 || old > 0 && new <= 0;
(new != 0).then_some(new)
} else {
state_change = update < 0;
(update != 0).then_some(-update)
}
}
};
});
state_change
}};
($task:ident, $key:ident $input:tt, $update:expr) => {
match $update {
update => {
Expand Down
Loading