mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 22:34:45 +00:00
Assign length when creating small str
This commit is contained in:
parent
4e0f591f8e
commit
af4c0348c6
1 changed files with 6 additions and 2 deletions
|
@ -243,7 +243,7 @@ impl RocStr {
|
||||||
pub fn empty() -> Self {
|
pub fn empty() -> Self {
|
||||||
RocStr {
|
RocStr {
|
||||||
// The first bit of length is 1 to specify small str.
|
// The first bit of length is 1 to specify small str.
|
||||||
length: isize::MIN as usize,
|
length: 0,
|
||||||
elements: core::ptr::null_mut(),
|
elements: core::ptr::null_mut(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -329,6 +329,10 @@ impl RocStr {
|
||||||
*target_ptr.offset(index) = *source_ptr.offset(index);
|
*target_ptr.offset(index) = *source_ptr.offset(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Write length and small string bit to last byte of length.
|
||||||
|
let mut bytes = rocstr.length.to_ne_bytes();
|
||||||
|
bytes[bytes.len() - 1] = capacity as u8 ^ 0b1000_0000;
|
||||||
|
rocstr.length = usize::from_ne_bytes(bytes);
|
||||||
rocstr
|
rocstr
|
||||||
} else {
|
} else {
|
||||||
let ptr = slice.as_ptr();
|
let ptr = slice.as_ptr();
|
||||||
|
@ -382,7 +386,7 @@ impl fmt::Debug for RocStr {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
// RocStr { is_small_str: false, storage: Refcounted(3), elements: [ 1,2,3,4] }
|
// RocStr { is_small_str: false, storage: Refcounted(3), elements: [ 1,2,3,4] }
|
||||||
f.debug_struct("RocStr")
|
f.debug_struct("RocStr")
|
||||||
.field("is_small_str", &false)
|
.field("is_small_str", &self.is_small_str())
|
||||||
.field("storage", &self.storage())
|
.field("storage", &self.storage())
|
||||||
.field("elements", &self.as_slice())
|
.field("elements", &self.as_slice())
|
||||||
.finish()
|
.finish()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue