Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions crates/core/src/db/datastore/locking_tx_datastore/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -816,17 +816,12 @@ impl TxState {
}
}

struct SequencesState {
#[derive(Default)]
pub struct SequencesState {
sequences: HashMap<SequenceId, Sequence>,
}

impl SequencesState {
pub fn new() -> Self {
Self {
sequences: HashMap::new(),
}
}

pub fn get_sequence_mut(&mut self, seq_id: SequenceId) -> Option<&mut Sequence> {
self.sequences.get_mut(&seq_id)
}
Expand Down Expand Up @@ -1832,7 +1827,7 @@ impl Locking {
Self {
memory: Arc::new(Mutex::new(BTreeMap::new())),
committed_state: Arc::new(RwLock::new(CommittedState::new())),
sequence_state: Arc::new(Mutex::new(SequencesState::new())),
sequence_state: Arc::new(Mutex::new(SequencesState::default())),
database_address,
}
}
Expand Down
9 changes: 7 additions & 2 deletions crates/sats/src/algebraic_value/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,16 @@ impl ser::Serializer for ValueSerializer {
///
/// - `total_len == chunks.map(|c| c.len()).sum() <= isize::MAX`
unsafe fn concat_byte_chunks<'a>(total_len: usize, chunks: impl Iterator<Item = &'a [u8]>) -> Vec<u8> {
if total_len == 0 {
return Vec::new();
}

// Allocate space for `[u8; total_len]` on the heap.
let layout = Layout::array::<u8>(total_len);
// SAFETY: Caller promised that `total_len <= isize`.
let layout = unsafe { layout.unwrap_unchecked() };
let ptr = alloc::alloc(layout);
// SAFETY: We checked above that `layout.size() != 0`.
let ptr = unsafe { alloc::alloc(layout) };
if ptr.is_null() {
alloc::handle_alloc_error(layout);
}
Expand Down Expand Up @@ -157,7 +162,7 @@ unsafe fn concat_byte_chunks<'a>(total_len: usize, chunks: impl Iterator<Item =
// - `total_len <= total_len` holds.
// - `total_len` values were initialized at type `u8`
// as we know `total_len == chunks.map(|c| c.len()).sum()`.
Vec::from_raw_parts(ptr, total_len, total_len)
unsafe { Vec::from_raw_parts(ptr, total_len, total_len) }
}

/// Continuation for serializing an array.
Expand Down
4 changes: 2 additions & 2 deletions crates/sats/src/bsatn/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ impl<W: BufWriter> ser::Serializer for Serializer<'_, W> {
value.serialize(self)
}

unsafe fn serialize_bsatn(self, ty: &crate::AlgebraicType, mut bsatn: &[u8]) -> Result<Self::Ok, Self::Error> {
debug_assert!(AlgebraicValue::decode(ty, &mut bsatn).is_ok());
unsafe fn serialize_bsatn(self, ty: &crate::AlgebraicType, bsatn: &[u8]) -> Result<Self::Ok, Self::Error> {
debug_assert!(AlgebraicValue::decode(ty, &mut { bsatn }).is_ok());
self.writer.put_slice(bsatn);
Ok(())
}
Expand Down