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

Implement beef::lean::Cow on other pointer widths #40

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
16 changes: 10 additions & 6 deletions src/lean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

use crate::traits::Capacity;

/// Faster, 2-word `Cow`. This version is available only on 64-bit architecture,
/// and it puts both capacity and length together in a fat pointer. Both length and capacity
/// is limited to 32 bits.
/// Faster, 2-word `Cow`.
///
/// This version puts both capacity and length together in a fat pointer.
/// Both length and capacity are stored evenly through out the target pointer's width.
///
/// For example, on a machine with a pointer width of 64. both length and capacity would occupy 32 bits.
///
/// # Panics
///
/// [`Cow::owned`](../generic/struct.Cow.html#method.owned) will panic if capacity is larger than `u32::max_size()`. Use the
/// top level `beef::Cow` if you wish to avoid this problem.
/// [`Cow::owned`](../generic/struct.Cow.html#method.owned) will panic if capacity is larger than half the pointer width.
/// Use the top level `beef::Cow` if you wish to avoid this problem.
pub type Cow<'a, T> = crate::generic::Cow<'a, T, Lean>;

pub(crate) mod internal {
Expand All @@ -18,7 +21,8 @@ pub(crate) mod internal {
}
use internal::Lean;

const MASK_LO: usize = u32::MAX as usize;
const POINTER_SIZE: usize = core::mem::size_of::<usize>() * 8;
const MASK_LO: usize = usize::MAX >> (POINTER_SIZE / 2);
const MASK_HI: usize = !MASK_LO;

impl Lean {
Expand Down
7 changes: 0 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,8 @@ mod wide;
mod serde;

pub mod generic;
#[cfg(target_pointer_width = "64")]
pub mod lean;

#[cfg(not(target_pointer_width = "64"))]
pub mod lean {
/// Re-exports 3-word Cow for non-64-bit targets
pub use super::wide::Cow;
}

pub use wide::Cow;

#[rustfmt::skip]
Expand Down