1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 06:16:04 +00:00

slight nbt optimizations

This commit is contained in:
mat 2021-12-20 01:04:18 -06:00
parent 91a26609f7
commit 5090ebe25f
3 changed files with 10 additions and 12 deletions

View file

@ -16,13 +16,13 @@ fn bench_serialize(filename: &str, c: &mut Criterion) {
let mut decoded_src_decoder = GzDecoder::new(&mut src);
let mut decoded_src = Vec::new();
decoded_src_decoder.read_to_end(&mut decoded_src).unwrap();
let mut decoded_src_stream = std::io::Cursor::new(decoded_src);
let mut decoded_src_stream = std::io::Cursor::new(decoded_src.clone());
file.seek(SeekFrom::Start(0)).unwrap();
let nbt = Tag::read_gzip(&mut file).unwrap();
let mut group = c.benchmark_group(filename);
group.throughput(Throughput::Bytes(contents.len() as u64));
group.throughput(Throughput::Bytes(decoded_src.len() as u64));
group.bench_function("Decode", |b| {
b.iter(|| {
decoded_src_stream.seek(SeekFrom::Start(0)).unwrap();
@ -38,7 +38,7 @@ fn bench_serialize(filename: &str, c: &mut Criterion) {
}
fn bench(c: &mut Criterion) {
// bench_serialize("tests/bigtest.nbt", c);
bench_serialize("tests/bigtest.nbt", c);
// bench_serialize("tests/simple_player.dat", c);
// bench_serialize("tests/complex_player.dat", c);
bench_serialize("tests/level.dat", c);

View file

@ -40,8 +40,8 @@ impl Tag {
writer
.write_i32::<BE>(value.len() as i32)
.map_err(|_| Error::WriteError)?;
for byte in value {
writer.write_i8(*byte).map_err(|_| Error::WriteError)?;
for &byte in value {
writer.write_i8(byte).map_err(|_| Error::WriteError)?;
}
}
Tag::String(value) => {
@ -77,19 +77,17 @@ impl Tag {
writer
.write_i32::<BE>(value.len() as i32)
.map_err(|_| Error::WriteError)?;
for int in value {
writer
.write_i32::<BE>(*int)
.map_err(|_| Error::WriteError)?;
for &int in value {
writer.write_i32::<BE>(int).map_err(|_| Error::WriteError)?;
}
}
Tag::LongArray(value) => {
writer
.write_i32::<BE>(value.len() as i32)
.map_err(|_| Error::WriteError)?;
for long in value {
for &long in value {
writer
.write_i64::<BE>(*long)
.write_i64::<BE>(long)
.map_err(|_| Error::WriteError)?;
}
}

View file

@ -1,6 +1,6 @@
use std::collections::HashMap;
#[derive(Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq)]
pub enum Tag {
End, // 0
Byte(i8), // 1