Skip to content

Commit

Permalink
🐛 Reduce allocations when using Crayons
Browse files Browse the repository at this point in the history
We need to convert a Crayon to string outside the function to avoid
allocations.
  • Loading branch information
ronisbr committed May 24, 2024
1 parent 2d515ff commit fe04213
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/SatelliteToolboxSgp4.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ include("types.jl")
const _JD_1900 = DateTime(1900, 1, 1, 12, 0, 0) |> datetime2julian

# Escape sequences related to the crayons.
const _D = Crayon(reset = true)
const _B = crayon"bold"
const _Y = crayon"yellow bold"
const _D = string(Crayon(reset = true))
const _B = string(crayon"bold")
const _Y = string(crayon"yellow bold")

############################################################################################
# Includes #
Expand Down
6 changes: 3 additions & 3 deletions src/tle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,9 @@ function fit_sgp4_tle!(

# Check if stdout supports colors.
has_color = get(stdout, :color, false)::Bool
cd = has_color ? string(_D) : ""
cb = has_color ? string(_B) : ""
cy = has_color ? string(_Y) : ""
cd = has_color ? _D : ""
cb = has_color ? _B : ""
cy = has_color ? _Y : ""

# Assemble the weight matrix.
W = Diagonal(
Expand Down

0 comments on commit fe04213

Please sign in to comment.