Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perf: return empty string instead of nothing in split1 #770

Merged
merged 2 commits into from
Dec 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/HDF5.jl
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ end
# Path manipulation
function split1(path::AbstractString)
ind = findfirst('/', path)
isnothing(ind) && return path, nothing
isnothing(ind) && return path, ""
if ind == 1 # matches root group
return "/", path[2:end]
else
Expand Down Expand Up @@ -914,7 +914,7 @@ function Base.haskey(parent::Union{File,Group}, path::AbstractString, lapl::Prop
return false
end
exists = true
if !isnothing(rest) && !isempty(rest)
if !isempty(rest)
obj = parent[first]
exists = haskey(obj, rest, lapl)
close(obj)
Expand Down
6 changes: 4 additions & 2 deletions test/plain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -872,10 +872,11 @@ end # show tests

@testset "split1" begin

@test HDF5.split1("a") == ("a", nothing)
@test HDF5.split1("/") == ("/", "")
@test HDF5.split1("a") == ("a", "")
@test HDF5.split1("/a/b/c") == ("/", "a/b/c")
@test HDF5.split1("a/b/c") == ("a", "b/c")
@test HDF5.split1(GenericString("a")) == ("a", nothing)
@test HDF5.split1(GenericString("a")) == ("a", "")
@test HDF5.split1(GenericString("/a/b/c")) == ("/", "a/b/c")
@test HDF5.split1(GenericString("a/b/c")) == ("a", "b/c")

Expand Down Expand Up @@ -908,6 +909,7 @@ hfile = h5open(fn, "w")
group1 = create_group(hfile, "group1")
group2 = create_group(group1, "group2")

@test haskey(hfile, "/")
@test haskey(hfile, GenericString("group1"))
@test !haskey(hfile, GenericString("groupna"))
@test haskey(hfile, "group1/group2")
Expand Down