JuliaLang/julia — pull request #5519 by kmsquire (2014-01-24 20:46:00+00:00)
Title: Added `get!` for Dicts

This PR refactors `setindex!(d::Dict, v, key)` into `setindex!` and `ht_keyindex2`, where `ht_keyindex2` returns either the current `index` of the key, or `-index` for the insertion location of a new key (after rehashing, etc).

(Compare with `ht_keyindex`, which returns `-1` if the key is not in the hash table, and does not call `rehash`.)

This is used by `get!` to get the current or new location of a key.

The PR does not have any measurable impact on performance.

Related:
* #1529, #2108
* #1764. I feel that a function is preferable to a macro for most users and most uses.
* https://github.com/JuliaLang/DataStructures.jl/pull/3
* Provides a `DefaultDict` implementation based on the Python one.
* Evaluates `ht_keyindex` more than once --> kills performance.

CC: @toivoh, @StefanKarpinski