JuliaCollections / LRUCache.jl
Showing 1 of 5 files from the diff.
Other files ignored by Codecov
.travis.yml has changed.
Project.toml has changed.
test/runtests.jl has changed.
.appveyor.yml has changed.

@@ -63,14 +63,15 @@
Loading
63 63
    end
64 64
end
65 65
function Base.get(default::Callable, lru::LRU, key)
66 -
    lock(lru.lock) do
67 -
        if _unsafe_haskey(lru, key)
68 -
            v = _unsafe_getindex(lru, key)
69 -
            return v
70 -
        else
71 -
            return default()
72 -
        end
66 +
    lock(lru.lock)
67 +
    if _unsafe_haskey(lru, key)
68 +
        v = _unsafe_getindex(lru, key)
69 +
        unlock(lru.lock)
70 +
        return v
71 +
    else
72 +
        unlock(lru.lock)
73 73
    end
74 +
    return default()
74 75
end
75 76
function Base.get!(lru::LRU, key, default)
76 77
    lock(lru.lock) do
@@ -85,16 +86,25 @@
Loading
85 86
    end
86 87
end
87 88
function Base.get!(default::Callable, lru::LRU, key)
88 -
    lock(lru.lock) do
89 -
        if _unsafe_haskey(lru, key)
90 -
            v = _unsafe_getindex(lru, key)
91 -
            return v
92 -
        end
93 -
        v = default()
89 +
    lock(lru.lock)
90 +
    if _unsafe_haskey(lru, key)
91 +
        v = _unsafe_getindex(lru, key)
92 +
        unlock(lru.lock)
93 +
        return v
94 +
    else
95 +
        unlock(lru.lock)
96 +
    end
97 +
    v = default()
98 +
    lock(lru.lock)
99 +
    if _unsafe_haskey(lru, key)
100 +
        # should we test that this yields the same result as default()
101 +
        v = _unsafe_getindex(lru, key)
102 +
    else
94 103
        _unsafe_addindex!(lru, v, key)
95 104
        _unsafe_resize!(lru)
96 -
        return v
97 105
    end
106 +
    unlock(lru.lock)
107 +
    return v
98 108
end
99 109
100 110
function _unsafe_getindex(lru::LRU, key)
Files Coverage
src 72.81%
Project Totals (2 files) 72.81%