Skip to content

Commit

Permalink
std::fmt: minor optimization for the Fprint function
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Aug 10, 2024
1 parent a62fa14 commit c459a8d
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions std/fmt/print.jule
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ use std::internal::strings::{StrBuilder}
// Prints arguments to file by default formatting.
// See documentation of format function for formatting.
fn Fprint(mut f: &File, args: ...any) {
mut buf := StrBuilder.New(20)
mut sb := StrBuilder.New(20)
for _, arg in args {
fmt::FmtByDefault(buf, arg)
f.Write(unsafe { buf.Buf() }) else {
fmt::FmtByDefault(sb, arg)
f.Write(unsafe { sb.Buf() }) else {
panic("std::fmt: Fprint: error occurs when printing")
}
buf.Clear()
// Do not use the [Clear] method to avoid making new allocations.
// The buffer used temporarily, so just clear the length, not capacity.
unsafe { sb.SetBuf(sb.Buf()[:0]) }
}
}

Expand Down

0 comments on commit c459a8d

Please sign in to comment.