From a5d542b502a4d4f64b1d213bc6c802d012a480bd Mon Sep 17 00:00:00 2001 From: Mustafa Mohamad Date: Wed, 9 Dec 2020 01:52:04 -0500 Subject: [PATCH 1/2] Perf: return empty string instead of nothing in split1 --- src/HDF5.jl | 4 ++-- test/plain.jl | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/HDF5.jl b/src/HDF5.jl index c490aec94..d46cc4d95 100644 --- a/src/HDF5.jl +++ b/src/HDF5.jl @@ -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 @@ -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) diff --git a/test/plain.jl b/test/plain.jl index 67f5bacce..f2ed5e4fc 100644 --- a/test/plain.jl +++ b/test/plain.jl @@ -872,10 +872,10 @@ end # show tests @testset "split1" begin -@test HDF5.split1("a") == ("a", nothing) +@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") From 65a345b7d2fee2f65b7e8ca82eff0a0e9840bf13 Mon Sep 17 00:00:00 2001 From: Mustafa M Date: Wed, 9 Dec 2020 02:07:13 -0500 Subject: [PATCH 2/2] Update plain.jl --- test/plain.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/plain.jl b/test/plain.jl index f2ed5e4fc..5d6930577 100644 --- a/test/plain.jl +++ b/test/plain.jl @@ -872,6 +872,7 @@ end # show tests @testset "split1" begin +@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") @@ -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")