Skip to content

Commit 3f2eed3

Browse files
authored
Refactored get function to use ternary operator for cleaner syntax (#57371)
1 parent 6dca4f4 commit 3f2eed3

File tree

1 file changed

+1
-6
lines changed

1 file changed

+1
-6
lines changed

base/strings/basic.jl

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,7 @@ getindex(s::AbstractString, v::AbstractVector{Bool}) =
196196
throw(ArgumentError("logical indexing not supported for strings"))
197197

198198
function get(s::AbstractString, i::Integer, default)
199-
# TODO: use ternary once @inbounds is expression-like
200-
if checkbounds(Bool, s, i)
201-
@inbounds return s[i]
202-
else
203-
return default
204-
end
199+
checkbounds(Bool, s, i) ? (@inbounds s[i]) : default
205200
end
206201

207202
## bounds checking ##

0 commit comments

Comments
 (0)