diff --git a/compact_str/src/lib.rs b/compact_str/src/lib.rs index 08244da4..559ebbeb 100644 --- a/compact_str/src/lib.rs +++ b/compact_str/src/lib.rs @@ -615,7 +615,7 @@ impl CompactString { /// ``` #[inline] pub fn as_bytes(&self) -> &[u8] { - &self.0.as_slice()[..self.len()] + self.0.as_slice() } // TODO: Implement a `try_as_mut_slice(...)` that will fail if it results in cloning? diff --git a/compact_str/src/repr/capacity.rs b/compact_str/src/repr/capacity.rs index bf63ff41..3d5e41a3 100644 --- a/compact_str/src/repr/capacity.rs +++ b/compact_str/src/repr/capacity.rs @@ -23,6 +23,7 @@ const HEAP_MARKER: usize = { /// /// All bytes `255`, with the last being [`LastUtf8Char::Heap`], using the same amount of bytes /// as `usize`. Example (64-bit): `[255, 255, 255, 255, 255, 255, 255, 216]` +#[cfg(not(target_pointer_width = "64"))] const CAPACITY_IS_ON_THE_HEAP: Capacity = Capacity(VALID_MASK | HEAP_MARKER); /// The maximum value we're able to store, e.g. on 64-bit arch this is 2^56 - 2. @@ -101,7 +102,13 @@ impl Capacity { /// stored on the heap #[inline(always)] pub fn is_heap(self) -> bool { - self == CAPACITY_IS_ON_THE_HEAP + cfg_if::cfg_if! { + if #[cfg(target_pointer_width = "64")] { + false + } else { + self == CAPACITY_IS_ON_THE_HEAP + } + } } } diff --git a/compact_str/src/tests.rs b/compact_str/src/tests.rs index d8893ca3..03b5919d 100644 --- a/compact_str/src/tests.rs +++ b/compact_str/src/tests.rs @@ -1914,7 +1914,7 @@ fn test_from_string_buffer_inlines_on_clone() { #[should_panic = "Cannot allocate memory to hold CompactString"] fn test_alloc_excessively_long_string() { // 2**56 - 2 bytes, the maximum number `Capacity` can hold - CompactString::with_capacity((1 << 56) - 2); + std::hint::black_box(CompactString::with_capacity((1 << 56) - 2)); } // This feature was enabled by which was first