Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Put len before xs for better memory layout #255

Merged
merged 1 commit into from Mar 7, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/array_string.rs
Expand Up @@ -31,10 +31,11 @@ use serde::{Serialize, Deserialize, Serializer, Deserializer};
/// The string is a contiguous value that you can store directly on the stack
/// if needed.
#[derive(Copy)]
#[repr(C)]
pub struct ArrayString<const CAP: usize> {
// the `len` first elements of the array are initialized
xs: [MaybeUninit<u8>; CAP],
len: LenUint,
xs: [MaybeUninit<u8>; CAP],
}

impl<const CAP: usize> Default for ArrayString<CAP>
Expand Down
3 changes: 2 additions & 1 deletion src/arrayvec.rs
Expand Up @@ -39,10 +39,11 @@ use crate::utils::MakeMaybeUninit;
///
/// It offers a simple API but also dereferences to a slice, so that the full slice API is
/// available. The ArrayVec can be converted into a by value iterator.
#[repr(C)]
pub struct ArrayVec<T, const CAP: usize> {
len: LenUint,
// the `len` first elements of the array are initialized
xs: [MaybeUninit<T>; CAP],
len: LenUint,
}

impl<T, const CAP: usize> Drop for ArrayVec<T, CAP> {
Expand Down