diff options
author | Philip Robinson <[email protected]> | 2011-04-27 22:42:18 +1000 |
---|---|---|
committer | Philip Robinson <[email protected]> | 2011-04-27 22:42:18 +1000 |
commit | 67a20c0e2f91e143536202ae969d8211e3ac3da8 (patch) | |
tree | c2b1e74237ab1c95a41fa11ee5769e03e169ef36 /lib/mnesia/src | |
parent | ef407fad10bccb97aab140f5b99786b8c7b2237a (diff) | |
download | otp-67a20c0e2f91e143536202ae969d8211e3ac3da8.tar.gz otp-67a20c0e2f91e143536202ae969d8211e3ac3da8.tar.bz2 otp-67a20c0e2f91e143536202ae969d8211e3ac3da8.zip |
Reduce calls to phash in key_to_frag_number
Original code calls phash 1..2 times, based on which fragment the hashed key
targets and how many fragments exist. New code always calls phash only once.
Diffstat (limited to 'lib/mnesia/src')
-rw-r--r-- | lib/mnesia/src/mnesia_frag_hash.erl | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/lib/mnesia/src/mnesia_frag_hash.erl b/lib/mnesia/src/mnesia_frag_hash.erl index 610ba2535c..d70579c3b3 100644 --- a/lib/mnesia/src/mnesia_frag_hash.erl +++ b/lib/mnesia/src/mnesia_frag_hash.erl @@ -101,21 +101,19 @@ del_frag(OldState) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -key_to_frag_number(#hash_state{function = phash, next_n_to_split = SplitN, n_doubles = L}, Key) -> - P = SplitN, - A = erlang:phash(Key, power2(L)), +key_to_frag_number(#hash_state{function = phash, n_fragments = N, n_doubles = L}, Key) -> + A = erlang:phash(Key, power2(L + 1)), if - A < P -> - erlang:phash(Key, power2(L + 1)); + A > N -> + A - power2(L); true -> A end; -key_to_frag_number(#hash_state{function = phash2, next_n_to_split = SplitN, n_doubles = L}, Key) -> - P = SplitN, - A = erlang:phash2(Key, power2(L)) + 1, +key_to_frag_number(#hash_state{function = phash2, n_fragments = N, n_doubles = L}, Key) -> + A = erlang:phash2(Key, power2(L + 1)) + 1, if - A < P -> - erlang:phash2(Key, power2(L + 1)) + 1; + A > N -> + A - power2(L); true -> A end; |