Skip to content

Commit

Permalink
Use standard div_cell (#547)
Browse files Browse the repository at this point in the history
# Objective

- Replace `num_integer::div_ceil` with the standard `div_ceil`.
- Closes #544

# Solution

[Rust 1.73.0 stabilized div_ceil for unsigned
integers.](https://blog.rust-lang.org/2023/10/05/Rust-1.73.0.html#stabilized-apis)

- Replaces `num_integer::div_ceil` with the standard `div_ceil`.
- Removes `num-integer` crate as a dependency because it is no longer
used.
  • Loading branch information
SelfMadeSystem authored Oct 8, 2023
1 parent b8ac380 commit b099ebf
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 10 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ lru = "0.11.0"
noise = "0.8.2"
num = "0.4.0"
num-bigint = "0.4.3"
num-integer = "0.1.45"
owo-colors = "3.5.0"
parking_lot = "0.12.1"
paste = "1.0.11"
Expand Down
3 changes: 1 addition & 2 deletions crates/valence_anvil/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ license.workspace = true

[features]
bevy_plugin = ["dep:bevy_app", "dep:bevy_ecs", "dep:flume", "parsing"]
parsing = ["dep:num-integer", "dep:valence_server"]
parsing = ["dep:valence_server"]

[dependencies]
bevy_app = { workspace = true, optional = true }
Expand All @@ -22,7 +22,6 @@ byteorder.workspace = true
flate2.workspace = true
flume = { workspace = true, optional = true }
lru.workspace = true
num-integer = { workspace = true, optional = true }
thiserror.workspace = true
valence_nbt = { workspace = true, features = ["binary"] }
valence_server = { workspace = true, optional = true }
5 changes: 2 additions & 3 deletions crates/valence_anvil/src/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::borrow::Cow;
use std::collections::BTreeMap;
use std::path::PathBuf;

use num_integer::div_ceil;
use thiserror::Error;
use valence_server::block::{PropName, PropValue};
use valence_server::layer::chunk::{Chunk, UnloadedChunk};
Expand Down Expand Up @@ -214,7 +213,7 @@ fn parse_chunk(

let bits_per_idx = bit_width(converted_block_palette.len() - 1).max(4);
let idxs_per_long = 64 / bits_per_idx;
let long_count = div_ceil(BLOCKS_PER_SECTION, idxs_per_long);
let long_count = BLOCKS_PER_SECTION.div_ceil(idxs_per_long);
let mask = 2_u64.pow(bits_per_idx as u32) - 1;

if long_count != data.len() {
Expand Down Expand Up @@ -281,7 +280,7 @@ fn parse_chunk(

let bits_per_idx = bit_width(converted_biome_palette.len() - 1);
let idxs_per_long = 64 / bits_per_idx;
let long_count = div_ceil(BIOMES_PER_SECTION, idxs_per_long);
let long_count = BIOMES_PER_SECTION.div_ceil(idxs_per_long);
let mask = 2_u64.pow(bits_per_idx as u32) - 1;

if long_count != data.len() {
Expand Down
1 change: 0 additions & 1 deletion crates/valence_server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,4 @@ valence_protocol.workspace = true
valence_generated.workspace = true
rustc-hash.workspace = true
parking_lot.workspace = true
num-integer.workspace = true
arrayvec.workspace = true
5 changes: 2 additions & 3 deletions crates/valence_server/src/layer/chunk/paletted_container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::array;
use std::io::Write;

use arrayvec::ArrayVec;
use num_integer::div_ceil;
use valence_protocol::{Encode, VarInt};

use super::chunk::bit_width;
Expand All @@ -28,7 +27,7 @@ impl<T: Copy + Eq + Default, const LEN: usize, const HALF_LEN: usize>
PalettedContainer<T, LEN, HALF_LEN>
{
pub(super) fn new() -> Self {
assert_eq!(div_ceil(LEN, 2), HALF_LEN);
assert_eq!(LEN.div_ceil(2), HALF_LEN);
assert_ne!(LEN, 0);

Self::Single(T::default())
Expand Down Expand Up @@ -261,7 +260,7 @@ impl<T: Copy + Eq + Default, const LEN: usize, const HALF_LEN: usize> Indirect<T
#[inline]
fn compact_u64s_len(vals_count: usize, bits_per_val: usize) -> usize {
let vals_per_u64 = 64 / bits_per_val;
div_ceil(vals_count, vals_per_u64)
vals_count.div_ceil(vals_per_u64)
}

#[inline]
Expand Down

0 comments on commit b099ebf

Please sign in to comment.