mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 14:24:45 +00:00
take self by reference
This commit is contained in:
parent
ca5efdf1d9
commit
04fa8fee38
1 changed files with 4 additions and 3 deletions
|
@ -308,16 +308,17 @@ pub const RocStr = extern struct {
|
|||
return (ptr - 1)[0] == utils.REFCOUNT_ONE;
|
||||
}
|
||||
|
||||
pub fn asSlice(self: RocStr) []u8 {
|
||||
pub fn asSlice(self: *RocStr) []u8 {
|
||||
return self.asU8ptr()[0..self.len()];
|
||||
}
|
||||
|
||||
pub fn asU8ptr(self: RocStr) [*]u8 {
|
||||
pub fn asU8ptr(self: *RocStr) [*]u8 {
|
||||
|
||||
// Since this conditional would be prone to branch misprediction,
|
||||
// make sure it will compile to a cmov.
|
||||
// return if (self.isSmallStr() or self.isEmpty()) (&@bitCast([@sizeOf(RocStr)]u8, self)) else (@ptrCast([*]u8, self.str_bytes));
|
||||
if (self.isSmallStr() or self.isEmpty()) {
|
||||
const as_int = @ptrToInt(&self);
|
||||
const as_int = @ptrToInt(self);
|
||||
const as_ptr = @intToPtr([*]u8, as_int);
|
||||
return as_ptr;
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue