mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
perf(db): use smallvec for mdbx table names (#11291)
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -7544,6 +7544,7 @@ dependencies = [
|
||||
"rand 0.8.5",
|
||||
"rand_xorshift",
|
||||
"reth-mdbx-sys",
|
||||
"smallvec",
|
||||
"tempfile",
|
||||
"thiserror",
|
||||
"tracing",
|
||||
|
||||
@ -12,6 +12,7 @@ cfg_if::cfg_if! {
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(feature = "tracy-allocator")] {
|
||||
type AllocatorWrapper = tracy_client::ProfiledAllocator<AllocatorInner>;
|
||||
tracy_client::register_demangler!();
|
||||
const fn new_allocator_wrapper() -> AllocatorWrapper {
|
||||
AllocatorWrapper::new(AllocatorInner {}, 100)
|
||||
}
|
||||
@ -23,9 +24,6 @@ cfg_if::cfg_if! {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "tracy-allocator")]
|
||||
tracy_client::register_demangler!();
|
||||
|
||||
/// Custom allocator.
|
||||
pub type Allocator = AllocatorWrapper;
|
||||
|
||||
|
||||
@ -19,14 +19,16 @@ byteorder = "1"
|
||||
derive_more.workspace = true
|
||||
indexmap = "2"
|
||||
parking_lot.workspace = true
|
||||
smallvec.workspace = true
|
||||
thiserror.workspace = true
|
||||
dashmap = { workspace = true, features = ["inline"], optional = true }
|
||||
tracing.workspace = true
|
||||
|
||||
dashmap = { workspace = true, features = ["inline"], optional = true }
|
||||
|
||||
[features]
|
||||
default = []
|
||||
return-borrowed = []
|
||||
read-tx-timeouts = ["dashmap", "dashmap/inline"]
|
||||
read-tx-timeouts = ["dep:dashmap"]
|
||||
|
||||
[dev-dependencies]
|
||||
pprof = { workspace = true, features = [
|
||||
|
||||
@ -4,7 +4,7 @@ use crate::{
|
||||
Environment, Transaction,
|
||||
};
|
||||
use ffi::MDBX_db_flags_t;
|
||||
use std::{ffi::CString, ptr};
|
||||
use std::{ffi::CStr, ptr};
|
||||
|
||||
/// A handle to an individual database in an environment.
|
||||
///
|
||||
@ -27,8 +27,13 @@ impl Database {
|
||||
name: Option<&str>,
|
||||
flags: MDBX_db_flags_t,
|
||||
) -> Result<Self> {
|
||||
let c_name = name.map(|n| CString::new(n).unwrap());
|
||||
let name_ptr = if let Some(c_name) = &c_name { c_name.as_ptr() } else { ptr::null() };
|
||||
let mut c_name_buf = smallvec::SmallVec::<[u8; 32]>::new();
|
||||
let c_name = name.map(|n| {
|
||||
c_name_buf.extend_from_slice(n.as_bytes());
|
||||
c_name_buf.push(0);
|
||||
CStr::from_bytes_with_nul(&c_name_buf).unwrap()
|
||||
});
|
||||
let name_ptr = if let Some(c_name) = c_name { c_name.as_ptr() } else { ptr::null() };
|
||||
let mut dbi: ffi::MDBX_dbi = 0;
|
||||
txn.txn_execute(|txn_ptr| {
|
||||
mdbx_result(unsafe { ffi::mdbx_dbi_open(txn_ptr, name_ptr, flags, &mut dbi) })
|
||||
|
||||
Reference in New Issue
Block a user