Skip to content

Commit 48d1290

Browse files
jakobnissenJeffBezanson
authored andcommitted
sMore efficient isempty(::String) (#33991)
1 parent 1ad5e49 commit 48d1290

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

base/strings/basic.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ julia> sizeof("∀")
157157
sizeof(s::AbstractString) = ncodeunits(s) * sizeof(codeunit(s))
158158
firstindex(s::AbstractString) = 1
159159
lastindex(s::AbstractString) = thisind(s, ncodeunits(s))
160+
isempty(s::AbstractString) = iszero(ncodeunits(s))
160161

161162
function getindex(s::AbstractString, i::Integer)
162163
@boundscheck checkbounds(s, i)

test/strings/basic.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ using Random
2020
@test s == "ab"
2121

2222
@test isempty(string())
23+
@test !isempty("abc")
24+
@test !isempty("∀∃")
25+
@test !isempty(GenericString("∀∃"))
26+
@test isempty(GenericString(""))
27+
@test !isempty(GenericString("abc"))
2328
@test eltype(GenericString) == Char
2429
@test firstindex("abc") == 1
2530
@test cmp("ab","abc") == -1

0 commit comments

Comments
 (0)