Skip to content

Commit

Permalink
beam_utils: Optimize index_labels_1/2
Browse files Browse the repository at this point in the history
The execution time for beam_utils:index_labels_1/2 is among
the longest in the beam_bool, beam_bsm, beam_receive, and
beam_trim compiler passes. Therefore it is worthwhile to do
the minor optimization of replacing a call to lists:dropwhile/2
with a special-purpose drop_labels function.
  • Loading branch information
bjorng committed Apr 22, 2015
1 parent 3722594 commit 8470558
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/compiler/src/beam_utils.erl
Expand Up @@ -612,13 +612,15 @@ is_reg_used_at_1(R, Lbl, St0) ->
end.

index_labels_1([{label,Lbl}|Is0], Acc) ->
Is = lists:dropwhile(fun({label,_}) -> true;
(_) -> false end, Is0),
Is = drop_labels(Is0),
index_labels_1(Is0, [{Lbl,Is}|Acc]);
index_labels_1([_|Is], Acc) ->
index_labels_1(Is, Acc);
index_labels_1([], Acc) -> gb_trees:from_orddict(sort(Acc)).

drop_labels([{label,_}|Is]) -> drop_labels(Is);
drop_labels(Is) -> Is.

%% Help functions for combine_heap_needs.

combine_alloc_lists(Al1, Al2) ->
Expand Down

0 comments on commit 8470558

Please sign in to comment.