Skip to content

Commit

Permalink
Refactored get function to use ternary operator for cleaner syntax (J…
Browse files Browse the repository at this point in the history
  • Loading branch information
mikymatt01 authored Feb 12, 2025
1 parent 6dca4f4 commit 3f2eed3
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions base/strings/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,7 @@ getindex(s::AbstractString, v::AbstractVector{Bool}) =
throw(ArgumentError("logical indexing not supported for strings"))

function get(s::AbstractString, i::Integer, default)
# TODO: use ternary once @inbounds is expression-like
if checkbounds(Bool, s, i)
@inbounds return s[i]
else
return default
end
checkbounds(Bool, s, i) ? (@inbounds s[i]) : default
end

## bounds checking ##
Expand Down

0 comments on commit 3f2eed3

Please sign in to comment.