Skip to content

Commit

Permalink
remove iter_tools
Browse files Browse the repository at this point in the history
we only used them for collect_vec. I think its worth the "effort" to write Vec type annotations ourself and have one big crate with way too may features we don't need less
  • Loading branch information
Snowiiii committed Dec 12, 2024
1 parent 43c3f03 commit f587cb6
Show file tree
Hide file tree
Showing 20 changed files with 56 additions and 99 deletions.
2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,3 @@ uuid = { version = "1.11.0", features = ["serde", "v3", "v4"] }
derive_more = { version = "1.0.0", features = ["full"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

itertools = "0.13.0"
2 changes: 0 additions & 2 deletions pumpkin-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,3 @@ num-derive.workspace = true

colored = "2"
md5 = "0.7.0"

enum_dispatch = "0.3.13"
2 changes: 0 additions & 2 deletions pumpkin-inventory/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ pumpkin-core = { path = "../pumpkin-core" }

log.workspace = true
rayon.workspace = true
itertools.workspace = true
crossbeam.workspace = true
tokio.workspace = true
thiserror.workspace = true

Expand Down
5 changes: 2 additions & 3 deletions pumpkin-inventory/src/crafting.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use itertools::Itertools;
use pumpkin_registry::{
flatten_3x3, get_tag_values, IngredientSlot, IngredientType, RecipeResult, TagCategory, RECIPES,
};
Expand Down Expand Up @@ -76,13 +75,13 @@ fn shapeless_crafting_match(
input: [[Option<ItemStack>; 3]; 3],
pattern: &[[[Option<IngredientSlot>; 3]; 3]],
) -> bool {
let mut pattern = pattern
let mut pattern: Vec<IngredientSlot> = pattern
.iter()
.flatten()
.flatten()
.flatten()
.cloned()
.collect_vec();
.collect();
for item in input.into_iter().flatten().flatten() {
if let Some(index) = pattern.iter().enumerate().find_map(|(i, recipe_item)| {
if ingredient_slot_check(recipe_item, item) {
Expand Down
5 changes: 2 additions & 3 deletions pumpkin-inventory/src/drag_handler.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::container_click::MouseDragType;
use crate::{Container, InventoryError};
use itertools::Itertools;
use num_traits::Euclid;
use pumpkin_world::item::ItemStack;
use std::collections::HashMap;
Expand Down Expand Up @@ -73,10 +72,10 @@ impl DragHandler {
Err(InventoryError::MultiplePlayersDragging)?
}
let mut slots = container.all_slots();
let slots_cloned = slots
let slots_cloned: Vec<Option<ItemStack>> = slots
.iter()
.map(|stack| stack.map(|item| item.to_owned()))
.collect_vec();
.collect();
let Some(carried_item) = maybe_carried_item else {
return Ok(());
};
Expand Down
1 change: 0 additions & 1 deletion pumpkin-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ proc-macro = true
[dependencies]
serde.workspace = true
serde_json.workspace = true
itertools.workspace = true

proc-macro2 = "1.0"
quote = "1.0"
Expand Down
1 change: 0 additions & 1 deletion pumpkin-protocol/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ pumpkin-core = { path = "../pumpkin-core" }
uuid.workspace = true
serde.workspace = true
thiserror.workspace = true
itertools.workspace = true
log.workspace = true
tokio.workspace = true
num-traits.workspace = true
Expand Down
7 changes: 3 additions & 4 deletions pumpkin-protocol/src/client/play/c_chunk_data.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::{bytebuf::ByteBuffer, BitSet, ClientPacket, VarInt};
use itertools::Itertools;

use pumpkin_macros::client_packet;
use pumpkin_world::{chunk::ChunkData, DIRECT_PALETTE_BITS};
Expand All @@ -26,7 +25,7 @@ impl ClientPacket for CChunkData<'_> {
data_buf.put_i16(block_count);
//// Block states

let palette = chunk.iter().dedup().collect_vec();
let palette = chunk;
// TODO: make dynamic block_size work
// TODO: make direct block_size work
enum PaletteType {
Expand Down Expand Up @@ -55,7 +54,7 @@ impl ClientPacket for CChunkData<'_> {

palette.iter().for_each(|id| {
// Palette
data_buf.put_var_int(&VarInt(**id as i32));
data_buf.put_var_int(&VarInt(*id as i32));
});
// Data array length
let data_array_len = chunk.len().div_ceil(64 / block_size as usize);
Expand All @@ -67,7 +66,7 @@ impl ClientPacket for CChunkData<'_> {
for block in block_clump.iter().rev() {
let index = palette
.iter()
.position(|b| *b == block)
.position(|b| b == block)
.expect("Its just got added, ofc it should be there");
out_long = out_long << block_size | (index as i64);
}
Expand Down
6 changes: 0 additions & 6 deletions pumpkin-registry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,3 @@ indexmap = { version = "2.7.0", features = ["serde"] }
serde.workspace = true
serde_json.workspace = true

rayon.workspace = true

num-traits.workspace = true
num-derive.workspace = true

itertools.workspace = true
4 changes: 1 addition & 3 deletions pumpkin-registry/src/recipe/recipe_formats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use super::super::recipe::RecipeType;
use super::read::{
ingredients::IngredientSlot, CraftingType, RecipeKeys, RecipeResult, RecipeTrait,
};
use itertools::Itertools;

pub struct ShapedCrafting {
keys: RecipeKeys,
pattern: [[Option<char>; 3]; 3],
Expand Down Expand Up @@ -85,7 +83,7 @@ impl RecipeTrait for ShapelessCrafting {

[v1, v2, v3]
})
.collect_vec()
.collect()
}

fn result(self) -> RecipeResult {
Expand Down
7 changes: 1 addition & 6 deletions pumpkin-world/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,20 @@ pumpkin-macros = { path = "../pumpkin-macros" }
tokio.workspace = true
rayon.workspace = true
derive_more.workspace = true
itertools.workspace = true
thiserror.workspace = true
serde.workspace = true
serde_json.workspace = true
log.workspace = true
parking_lot.workspace = true

num-traits.workspace = true
num-derive.workspace = true
futures = "0.3"
dashmap = "6.1.0"

# Compression
# Compression
flate2 = "1.0"
lz4 = "1.28.0"

enum_dispatch = "0.3.13"
derive-getters = "0.5.0"

fastnbt = { git = "https://github.com/owengage/fastnbt.git" }

Expand All @@ -39,7 +35,6 @@ rand = "0.8.5"
[dev-dependencies]
criterion = { version = "0.5.1", features = ["html_reports"] }


[[bench]]
name = "chunk_noise"
harness = false
Expand Down
5 changes: 2 additions & 3 deletions pumpkin-world/src/chunk/anvil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::{
};

use flate2::bufread::{GzDecoder, ZlibDecoder};
use itertools::Itertools;

use crate::level::SaveFile;

Expand Down Expand Up @@ -143,7 +142,7 @@ impl ChunkReader for AnvilChunkReader {
};

// TODO: check checksum to make sure chunk is not corrupted
let header = file_buf.drain(0..5).collect_vec();
let header: Vec<u8> = file_buf.drain(0..5).collect();

let compression = Compression::from_byte(header[4]).ok_or(
ChunkReadingError::Compression(CompressionError::UnknownCompression),
Expand All @@ -152,7 +151,7 @@ impl ChunkReader for AnvilChunkReader {
let size = u32::from_be_bytes(header[..4].try_into().unwrap());

// size includes the compression scheme byte, so we need to subtract 1
let chunk_data = file_buf.drain(0..size as usize - 1).collect_vec();
let chunk_data = file_buf.drain(0..size as usize - 1).collect();
let decompressed_chunk = compression
.decompress_data(chunk_data)
.map_err(ChunkReadingError::Compression)?;
Expand Down
3 changes: 1 addition & 2 deletions pumpkin-world/src/cylindrical_chunk_iterator.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use itertools::Itertools;
use pumpkin_core::math::vector2::Vector2;

#[derive(Debug, Clone, Copy, PartialEq)]
Expand Down Expand Up @@ -76,7 +75,7 @@ impl Cylindrical {
all_chunks
.into_iter()
.filter(|chunk| self.is_within_distance(chunk.x, chunk.z))
.collect_vec()
.collect()
}
}

Expand Down
21 changes: 10 additions & 11 deletions pumpkin-world/src/world_gen/noise/density/spline.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::{marker::PhantomData, sync::Arc};

use enum_dispatch::enum_dispatch;
use itertools::Itertools;

use crate::world_gen::noise::lerp;

Expand Down Expand Up @@ -302,13 +301,13 @@ impl<E: DensityFunctionEnvironment, R: ComponentReference<E>> MutableSpline<E, R
.iter()
.all(|point| matches!(point, SplinePoint::Immutable(_)))
{
let immutable_points = converted_points
let immutable_points: Vec<ImmutablePoint> = converted_points
.into_iter()
.map(|point| match point {
SplinePoint::Immutable(point) => point,
_ => unreachable!(),
})
.collect_vec();
.collect();
SplineRef::Immutable(
ImmutableSpline {
function: shared,
Expand Down Expand Up @@ -387,7 +386,7 @@ impl<E: DensityFunctionEnvironment, R: ComponentReference<E>> MutableSplineImpl<
let converted_points = points
.into_iter()
.map(|point| point.convert(converter))
.collect_vec();
.collect();

Self::create_new_spline(converted_base, converted_points)
}
Expand All @@ -398,7 +397,7 @@ impl<E: DensityFunctionEnvironment, R: ComponentReference<E>> MutableSplineImpl<
.points
.iter()
.map(|point| point.clone_to_new_point())
.collect_vec();
.collect();

Self::create_new_spline(cloned_function, cloned_points)
}
Expand Down Expand Up @@ -462,18 +461,18 @@ impl ImmutableSplineRef {
converter: &mut dyn ConverterImpl<E>,
) -> Option<SplineRef<E>> {
let converted_base = self.0.function.maybe_convert(converter);
let maybe_converted_points = self
let maybe_converted_points: Vec<Option<SplinePoint<E>>> = self
.0
.points
.iter()
.map(|point| point.maybe_convert(converter))
.collect_vec();
.collect();

if converted_base.is_none() && maybe_converted_points.iter().all(|point| point.is_none()) {
None
} else {
let converted_base = converted_base.unwrap_or_else(|| self.0.function.clone().into());
let converted_points = maybe_converted_points
let converted_points: Vec<SplinePoint<E>> = maybe_converted_points
.into_iter()
.enumerate()
.map(|(index, point)| {
Expand All @@ -483,21 +482,21 @@ impl ImmutableSplineRef {
self.0.points[index].clone().into()
}
})
.collect_vec();
.collect();

Some(match converted_base {
ComponentReferenceImplementation::Shared(shared) => {
if converted_points
.iter()
.all(|point| matches!(point, SplinePoint::Immutable(_)))
{
let immutable_points = converted_points
let immutable_points: Vec<ImmutablePoint> = converted_points
.into_iter()
.map(|point| match point {
SplinePoint::Immutable(point) => point,
_ => unreachable!(),
})
.collect_vec();
.collect();
SplineRef::Immutable(
ImmutableSpline {
function: shared,
Expand Down
36 changes: 11 additions & 25 deletions pumpkin-world/src/world_gen/noise/perlin.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::sync::Arc;

use itertools::{izip, Itertools};
use num_traits::Pow;
use pumpkin_core::random::RandomGenerator;

Expand Down Expand Up @@ -226,19 +225,6 @@ impl OctavePerlinNoiseSampler {
random.skip(262);
}
}

#[cfg(debug_assertions)]
{
use itertools::Itertools;
use num_traits::Zero;

if let Ok(length1) = samplers.iter().filter(|x| x.is_some()).try_len() {
if let Ok(length2) = amplitudes.iter().filter(|x| !x.is_zero()).try_len() {
assert_eq!(length1, length2);
}
}
assert!(j >= i as i32 - 1);
}
} else {
let splitter = random.next_splitter();
for k in 0..i {
Expand All @@ -256,20 +242,20 @@ impl OctavePerlinNoiseSampler {
let mut lacunarity = 2f64.pow((-j) as f64);
let max_value = Self::get_total_amplitude(2f64, persistence, amplitudes);

let persistences = (0..amplitudes.len())
let persistences: Vec<f64> = (0..amplitudes.len())
.map(|_| {
let result = persistence;
persistence /= 2f64;
result
})
.collect_vec();
let lacunarities = (0..amplitudes.len())
.collect();
let lacunarities: Vec<f64> = (0..amplitudes.len())
.map(|_| {
let result = lacunarity;
lacunarity *= 2f64;
result
})
.collect_vec();
.collect();

Self {
octave_samplers: samplers.into(),
Expand All @@ -284,13 +270,13 @@ impl OctavePerlinNoiseSampler {
pub fn sample(&self, x: f64, y: f64, z: f64) -> f64 {
let mut d = 0f64;

for (sampler, amplitude, persistence, lacunarity) in izip!(
&self.octave_samplers,
&self.amplitudes,
&self.persistences,
&self.lacunarities
) {
if let Some(sampler) = sampler {
let num_octaves = self.octave_samplers.len();
for i in 0..num_octaves {
if let Some(sampler) = &self.octave_samplers[i] {
let lacunarity = self.lacunarities[i];
let amplitude = self.amplitudes[i];
let persistence = self.persistences[i];

let g = sampler.sample_no_fade(
Self::maintain_precision(x * lacunarity),
Self::maintain_precision(y * lacunarity),
Expand Down
Loading

0 comments on commit f587cb6

Please sign in to comment.