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

De-duplicate block sizes #835

Merged
merged 3 commits into from
Mar 5, 2024
Merged

De-duplicate block sizes #835

merged 3 commits into from
Mar 5, 2024

Conversation

scottopell
Copy link
Contributor

What does this PR do?

Refactors the generators that take in block_sizes as an argument and extracts that logic and default to a single location in the code.

Motivation

Simplify my next set of changes and de-duplicate the code.

Related issues

Additional Notes

@scottopell scottopell requested a review from a team as a code owner March 5, 2024 16:04
@scottopell scottopell force-pushed the sopell/dedup-block-sizes branch from 4bc9d01 to f263ca1 Compare March 5, 2024 16:07
.iter()
.map(|sz| NonZeroU32::new(sz.get_bytes() as u32).expect("bytes must be non-zero"))
.collect();
// TODO pass in datagram_friendly: true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a TODO here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

intentional, this will be the next PR

Comment on lines +750 to +775
#[must_use]
/// The default block sizes.
///
/// Panics are not possible in practice due to these being static values.
/// # Panics
/// - Panics if a block size is not representable as a 32bit integer
/// - Panics if a block size is zero
pub fn default_blocks() -> Vec<NonZeroU32> {
[
byte_unit::Byte::from_unit(1.0 / 32.0, byte_unit::ByteUnit::MB).expect("valid bytes"),
byte_unit::Byte::from_unit(1.0 / 16.0, byte_unit::ByteUnit::MB).expect("valid bytes"),
byte_unit::Byte::from_unit(1.0 / 4.0, byte_unit::ByteUnit::MB).expect("valid bytes"),
byte_unit::Byte::from_unit(1.0 / 2.0, byte_unit::ByteUnit::MB).expect("valid bytes"),
byte_unit::Byte::from_unit(1.0, byte_unit::ByteUnit::MB).expect("valid bytes"),
byte_unit::Byte::from_unit(2.0, byte_unit::ByteUnit::MB).expect("valid bytes"),
byte_unit::Byte::from_unit(4.0, byte_unit::ByteUnit::MB).expect("valid bytes"),
]
.iter()
.map(|sz| {
NonZeroU32::new(
u32::try_from(sz.get_bytes()).expect("Block size not representable as 32bit integer"),
)
.expect("Block size is non-zero")
})
.collect()
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is so much nicer than having this copied everywhere.

@scottopell scottopell enabled auto-merge (squash) March 5, 2024 17:54
@scottopell scottopell merged commit c620cb4 into main Mar 5, 2024
16 checks passed
@scottopell scottopell deleted the sopell/dedup-block-sizes branch March 5, 2024 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants