Skip to content

Commit

Permalink
Improve Map.get_or_else performance (#1482)
Browse files Browse the repository at this point in the history
This commit introduces a change so that, when a key isn't found during
a `get_or_else` call, that we do not have an error thrown. Instead,
we do a search for the key directly rather than going through the
`apply` method that might throw said error.
  • Loading branch information
SeanTAllen authored and jemc committed Dec 25, 2016
1 parent fee5e5c commit 440da84
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/collections/map.pony
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,16 @@ class HashMap[K, V, H: HashFunction[K] val]
Get the value associated with provided key if present. Otherwise,
return the provided alternate value.
"""
try
apply(key)
(let i, let found) = _search(key)

if found then
try
_array(i) as (_, this->V)
else
// This should never happen as we have already
// proven that _array(i) exists
consume alt
end
else
consume alt
end
Expand Down

0 comments on commit 440da84

Please sign in to comment.