diff --git a/twilight-gateway/src/lib.rs b/twilight-gateway/src/lib.rs index ec5471ebad..4b9a3e4639 100644 --- a/twilight-gateway/src/lib.rs +++ b/twilight-gateway/src/lib.rs @@ -100,6 +100,7 @@ pub const API_VERSION: u8 = 10; /// /// Panics if the bucket id is greater than or equal to the total number of /// buckets. +#[inline] #[track_caller] pub fn bucket( bucket_id: u16, @@ -115,6 +116,10 @@ pub fn bucket( let len = q + u32::from(bucket_id < r); let start = bucket_id * q + r.min(bucket_id); + // Compiler hint deduced from mathematical proof. + if shards < start + len { + std::process::abort(); + } (start..start + len).map(move |id| ShardId::new(id, shards)) } diff --git a/twilight-model/src/gateway/id.rs b/twilight-model/src/gateway/id.rs index c1acb069b6..d4ddcd6b02 100644 --- a/twilight-model/src/gateway/id.rs +++ b/twilight-model/src/gateway/id.rs @@ -127,6 +127,7 @@ impl ShardId { /// /// Panics if the shard number is greater than or equal to the total number /// of shards. + #[inline] pub const fn new(number: u32, total: u32) -> Self { assert!(number < total, "number must be less than total"); Self { @@ -137,6 +138,7 @@ impl ShardId { /// Create a new shard identifier if the shard indexes are valid. #[allow(clippy::missing_panics_doc)] + #[inline] pub const fn new_checked(number: u32, total: u32) -> Option { if number < total { Some(Self {