Permalink
Browse files

chash:successors/3: Avoiding an expensive list split when we need the…

… entire list anyway
  • Loading branch information...
esstrifork authored and Vagabond committed Apr 8, 2011
1 parent d3dd32a commit 0cd20ed57d1aecce8cabee081e7ab7583c2d3a50
Showing with 8 additions and 2 deletions.
  1. +8 −2 src/chash.erl
View
@@ -101,8 +101,14 @@ successors(Index, CHash) ->
% -> [NodeEntry]
successors(Index, CHash, N) ->
Num = max_n(N, CHash),
- {Res, _} = lists:split(Num, ordered_from(Index, CHash)),
- Res.
+ Ordered = ordered_from(Index, CHash),
+ {NumPartitions, _Nodes} = CHash,
+ if Num =:= NumPartitions ->
+ Ordered;
+ true ->
+ {Res, _} = lists:split(Num, Ordered),
+ Res
+ end.
% @doc Given an object key, return all NodeEntries in reverse order
% starting at Index.

0 comments on commit 0cd20ed

Please sign in to comment.