mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 16:21:11 +00:00
Don't hardcode 16 bytes in str.zig
This commit is contained in:
parent
89996c4b43
commit
6b8c39c8cb
1 changed files with 2 additions and 2 deletions
|
@ -17,7 +17,7 @@ const InPlace = packed enum(u8) {
|
||||||
|
|
||||||
const SMALL_STR_MAX_LENGTH = small_string_size - 1;
|
const SMALL_STR_MAX_LENGTH = small_string_size - 1;
|
||||||
const small_string_size = 2 * @sizeOf(usize);
|
const small_string_size = 2 * @sizeOf(usize);
|
||||||
const blank_small_string: [16]u8 = init_blank_small_string(small_string_size);
|
const blank_small_string: [@sizeOf(RocStr)]u8 = init_blank_small_string(small_string_size);
|
||||||
|
|
||||||
fn init_blank_small_string(comptime n: usize) [n]u8 {
|
fn init_blank_small_string(comptime n: usize) [n]u8 {
|
||||||
var prime_list: [n]u8 = undefined;
|
var prime_list: [n]u8 = undefined;
|
||||||
|
@ -246,7 +246,7 @@ pub const RocStr = extern struct {
|
||||||
pub fn asU8ptr(self: RocStr) [*]u8 {
|
pub fn asU8ptr(self: RocStr) [*]u8 {
|
||||||
// Since this conditional would be prone to branch misprediction,
|
// Since this conditional would be prone to branch misprediction,
|
||||||
// make sure it will compile to a cmov.
|
// make sure it will compile to a cmov.
|
||||||
return if (self.isSmallStr() or self.isEmpty()) (&@bitCast([16]u8, self)) else (@ptrCast([*]u8, self.str_bytes));
|
return if (self.isSmallStr() or self.isEmpty()) (&@bitCast([@sizeOf(RocStr)]u8, self)) else (@ptrCast([*]u8, self.str_bytes));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Given a pointer to some bytes, write the first (len) bytes of this
|
// Given a pointer to some bytes, write the first (len) bytes of this
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue