Skip to content

Commit

Permalink
std::unsafe: minor optimization for the StrFromBytes function
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Aug 12, 2024
1 parent ad2706e commit 218f3ba
Showing 1 changed file with 1 addition and 10 deletions.
11 changes: 1 addition & 10 deletions std/unsafe/conv.jule
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,7 @@ fn BytesStr(b: []byte): str {
}

// Same as [BytesStr] but keeps garbage collection.
fn StrFromBytes(b: []byte): str {
s := BytesStr(b)
unsafe {
if integ::Emit[bool]("{}.data.ref != {}", b, nil) {
integ::Emit("{}.buffer.ref = {}.data.ref", s, b)
integ::Emit("{}.buffer.add_ref()", s)
}
}
ret s
}
fn StrFromBytes(b: []byte): str { ret unsafe { *(*str)(&b) } }

// Same as [StrBytes] but keeps garbage collection.
fn BytesFromStr(s: str): []byte {
Expand Down

0 comments on commit 218f3ba

Please sign in to comment.