diff --git a/Cargo.toml b/Cargo.toml index 239cae0..abc36b3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,6 @@ arrayref = { version = "0.3", optional = true } arrayvec = { version = "0.7", optional = true } bytes = { version = "1", optional = true } bitflags = "2" -byteorder = "1" ciborium = { version = "0.2", optional = true } derive_more = "0.99" impls = { version = "1", optional = true } diff --git a/src/database.rs b/src/database.rs index 8eba400..d11d501 100644 --- a/src/database.rs +++ b/src/database.rs @@ -4,7 +4,6 @@ use crate::{ transaction::{RO, RW}, Mode, ReadWriteOptions, SyncMode, Transaction, TransactionKind, }; -use byteorder::{ByteOrder, NativeEndian}; use libc::c_uint; use mem::size_of; use sealed::sealed; @@ -14,6 +13,7 @@ use std::{ fmt::Debug, marker::PhantomData, mem, + ops::Deref, os::unix::ffi::OsStrExt, path::Path, ptr, result, @@ -378,7 +378,7 @@ where /// Note: /// /// * MDBX stores all the freelists in the designated table 0 in each database, - /// and the freelist count is stored at the beginning of the value as `libc::size_t` + /// and the freelist count is stored at the beginning of the value as 32-bit integer /// in the native byte order. /// /// * It will create a read transaction to traverse the freelist table. @@ -390,16 +390,13 @@ where for result in cursor { let (_key, value) = result?; - if value.len() < mem::size_of::() { + if value.len() < mem::size_of::() { return Err(Error::Corrupted); } - let s = &value[..mem::size_of::()]; - if cfg!(target_pointer_width = "64") { - freelist += NativeEndian::read_u64(s) as usize; - } else { - freelist += NativeEndian::read_u32(s) as usize; - } + freelist += + u32::from_ne_bytes(value.deref()[..mem::size_of::()].try_into().unwrap()) + as usize; } Ok(freelist) diff --git a/src/lib.rs b/src/lib.rs index f9c6dca..343cef3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -46,7 +46,6 @@ pub use orm_uses::*; #[cfg(test)] mod test_utils { use super::*; - use byteorder::{ByteOrder, LittleEndian}; use tempfile::tempdir; type Database = crate::Database; @@ -69,9 +68,8 @@ mod test_utils { ) .unwrap(); - for height in 0..1000 { - let mut value = [0u8; 8]; - LittleEndian::write_u64(&mut value, height); + for height in 0..1000_u64 { + let value = height.to_le_bytes(); let tx = db.begin_rw_txn().unwrap(); let index = tx.create_table(None, TableFlags::DUP_SORT).unwrap(); tx.put(&index, HEIGHT_KEY, value, WriteFlags::empty()) diff --git a/tests/environment.rs b/tests/environment.rs index 0d98b0a..95b17e0 100644 --- a/tests/environment.rs +++ b/tests/environment.rs @@ -1,4 +1,3 @@ -use byteorder::{ByteOrder, LittleEndian}; use libmdbx::*; use tempfile::tempdir; @@ -146,9 +145,8 @@ fn test_stat() { assert_eq!(stat.entries(), 0); // Write a few small values. - for i in 0..64 { - let mut value = [0u8; 8]; - LittleEndian::write_u64(&mut value, i); + for i in 0..64_u64 { + let value = i.to_le_bytes(); let tx = db.begin_rw_txn().unwrap(); tx.put( &tx.open_table(None).unwrap(), @@ -190,9 +188,8 @@ fn test_freelist() { assert_eq!(freelist, 0); // Write a few small values. - for i in 0..64 { - let mut value = [0u8; 8]; - LittleEndian::write_u64(&mut value, i); + for i in 0..64_u64 { + let value = i.to_le_bytes(); let tx = db.begin_rw_txn().unwrap(); tx.put( &tx.open_table(None).unwrap(),