Skip to content

Commit

Permalink
builtin: reduce a bit the generated #if defined checks for small prog…
Browse files Browse the repository at this point in the history
…rams (#23484)
  • Loading branch information
spytheman authored Jan 16, 2025
1 parent 6b92f8f commit 12d8f17
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
22 changes: 10 additions & 12 deletions vlib/builtin/builtin.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -346,21 +346,19 @@ pub fn println(s string) {

@[manualfree]
fn _writeln_to_fd(fd int, s string) {
$if !builtin_writeln_should_write_at_once ? {
$if builtin_writeln_should_write_at_once ? {
unsafe {
buf_len := s.len + 1 // space for \n
mut buf := malloc(buf_len)
C.memcpy(buf, s.str, s.len)
buf[s.len] = `\n`
_write_buf_to_fd(fd, buf, buf_len)
free(buf)
}
} $else {
lf := u8(`\n`)
_write_buf_to_fd(fd, s.str, s.len)
_write_buf_to_fd(fd, &lf, 1)
return
}
unsafe {
buf_len := s.len + 1 // space for \n
mut buf := malloc(buf_len)
defer {
free(buf)
}
C.memcpy(buf, s.str, s.len)
buf[s.len] = `\n`
_write_buf_to_fd(fd, buf, buf_len)
}
}

Expand Down
4 changes: 1 addition & 3 deletions vlib/builtin/utf8.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,12 @@ pub fn string_from_wide2(_wstr &u16, len int) string {
}
} $else {
mut sb := strings.new_builder(len)
defer {
unsafe { sb.free() }
}
for i := 0; i < len; i++ {
u := unsafe { rune(_wstr[i]) }
sb.write_rune(u)
}
res := sb.str()
unsafe { sb.free() }
return res
}
}
Expand Down

0 comments on commit 12d8f17

Please sign in to comment.