mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 06:44:46 +00:00
Use ::default over ::empty for RocStr and RocList
This commit is contained in:
parent
91f1589f62
commit
1c09450103
2 changed files with 21 additions and 17 deletions
|
@ -1955,7 +1955,7 @@ fn lists_with_incompatible_type_param_in_if() {
|
|||
""
|
||||
"#
|
||||
),
|
||||
RocStr::empty(),
|
||||
RocStr::default(),
|
||||
RocStr
|
||||
);
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ pub enum RocOrder {
|
|||
//#[macro_export]
|
||||
//macro_rules! roclist {
|
||||
// () => (
|
||||
// $crate::RocList::empty()
|
||||
// $crate::RocList::default()
|
||||
// );
|
||||
// ($($x:expr),+ $(,)?) => (
|
||||
// $crate::RocList::from_slice(&[$($x),+])
|
||||
|
@ -60,13 +60,6 @@ impl<T> RocList<T> {
|
|||
self.length == 0
|
||||
}
|
||||
|
||||
pub fn empty() -> Self {
|
||||
Self {
|
||||
length: 0,
|
||||
elements: core::ptr::null_mut(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get(&self, index: usize) -> Option<&T> {
|
||||
if index < self.len() {
|
||||
Some(unsafe {
|
||||
|
@ -287,6 +280,15 @@ impl<T> RocList<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> Default for RocList<T> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
length: 0,
|
||||
elements: core::ptr::null_mut(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: fmt::Debug> fmt::Debug for RocList<T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
// RocList { storage: Refcounted(3), elements: [ 1,2,3,4] }
|
||||
|
@ -367,13 +369,6 @@ impl RocStr {
|
|||
(self.length as isize) < 0
|
||||
}
|
||||
|
||||
pub fn empty() -> Self {
|
||||
RocStr {
|
||||
length: 0,
|
||||
elements: core::ptr::null_mut(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get(&self, index: usize) -> Option<&u8> {
|
||||
if index < self.len() {
|
||||
Some(unsafe {
|
||||
|
@ -460,7 +455,7 @@ impl RocStr {
|
|||
capacity
|
||||
);
|
||||
if capacity < core::mem::size_of::<Self>() {
|
||||
let mut rocstr = Self::empty();
|
||||
let mut rocstr = Self::default();
|
||||
let target_ptr = rocstr.get_small_str_ptr_mut();
|
||||
let source_ptr = slice.as_ptr() as *const u8;
|
||||
for index in 0..slice.len() {
|
||||
|
@ -548,6 +543,15 @@ impl RocStr {
|
|||
}
|
||||
}
|
||||
|
||||
impl Default for RocStr {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
length: 0,
|
||||
elements: core::ptr::null_mut(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&str> for RocStr {
|
||||
fn from(str: &str) -> Self {
|
||||
Self::from_slice(str.as_bytes())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue