allocate empty partial strings
This commit is contained in:
@@ -111,11 +111,25 @@ impl PartialString {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub(super)
|
pub(super)
|
||||||
fn empty() -> Self {
|
fn empty() -> Self {
|
||||||
PartialString {
|
let mut pstr = PartialString {
|
||||||
buf: &"\u{0}".as_bytes()[0] as *const _,
|
buf: ptr::null(),
|
||||||
len: '\u{0}'.len_utf8(),
|
len: 0,
|
||||||
_marker: PhantomData,
|
_marker: PhantomData,
|
||||||
|
};
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
let layout = alloc::Layout::from_size_align_unchecked(
|
||||||
|
'\u{0}'.len_utf8(),
|
||||||
|
mem::align_of::<u8>(),
|
||||||
|
);
|
||||||
|
|
||||||
|
pstr.buf = alloc::alloc(layout) as *const _;
|
||||||
|
pstr.len = '\u{0}'.len_utf8();
|
||||||
|
|
||||||
|
pstr.write_terminator_at(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pstr
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn append_chars(mut self, src: &str) -> Option<(Self, &str)> {
|
unsafe fn append_chars(mut self, src: &str) -> Option<(Self, &str)> {
|
||||||
|
|||||||
Reference in New Issue
Block a user