Skip to content

Commit

Permalink
Turn std.stdio types into inline types
Browse files Browse the repository at this point in the history
There's no real reason to keep these types as heap types, and turning
them into inline types makes it less expensive to create ad-hoc
instances of e.g. the Stdout type.

Changelog: performance
  • Loading branch information
yorickpeterse committed Jan 31, 2025
1 parent a0af0ac commit ad49ce7
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions std/src/std/stdio.inko
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ import std.io (Error, Read, Write, WriteInternal)
import std.sys.unix.stdio (self as sys) if unix

# The standard input stream of the current OS process.
#
# `Stdin` is allocated on the heap as this allows one to cast it to a trait,
# such as the `Read` trait.
type pub Stdin {
type pub inline Stdin {
let @fd: Int32

# Returns a new `Stdin`.
Expand Down Expand Up @@ -67,9 +64,6 @@ impl Read for Stdin {

# The standard output stream of the current OS process.
#
# `Stdout` is allocated on the heap as this allows one to cast it to a trait,
# such as the `Write` trait.
#
# # Buffering
#
# This output stream _does not_ use any form of buffering and instead writes its
Expand All @@ -80,7 +74,7 @@ impl Read for Stdin {
# reason for this is simple: it's easy to apply buffering by combining `Stdout`
# with existing types, but opting out of buffering would require additional
# flags or types, resulting in a messy API.
type pub Stdout {
type pub inline Stdout {
let @fd: Int32

# Returns a new `Stdout`.
Expand Down Expand Up @@ -127,15 +121,12 @@ impl Write for Stdout {

# The standard error stream of the current OS process.
#
# `Stdout` is allocated on the heap as this allows one to cast it to a trait,
# such as the `Write` trait.
#
# # Buffering
#
# This output stream _does not_ use any form of buffering and instead writes its
# output directly. If buffering is desired, you can do so by wrapping a `Stdout`
# in a `std.io.BufferedWriter`.
type pub Stderr {
type pub inline Stderr {
let @fd: Int32

# Returns a new `Stderr`.
Expand Down

0 comments on commit ad49ce7

Please sign in to comment.