From 04fa8fee386488f4551302d7225baf5bdedd683e Mon Sep 17 00:00:00 2001 From: Folkert Date: Tue, 24 Aug 2021 20:24:21 +0200 Subject: [PATCH] take self by reference --- compiler/builtins/bitcode/src/str.zig | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/compiler/builtins/bitcode/src/str.zig b/compiler/builtins/bitcode/src/str.zig index 600a40a632..65a4b0f37e 100644 --- a/compiler/builtins/bitcode/src/str.zig +++ b/compiler/builtins/bitcode/src/str.zig @@ -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 {