Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Ledest:erlang:23
erlang
5221-Slightly-optimize-lists-enumerate-1-2.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 5221-Slightly-optimize-lists-enumerate-1-2.patch of Package erlang
From ddbb190b3fd4051651d5021e54997a50c4c953fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= <bjorn@erlang.org> Date: Mon, 21 Feb 2022 14:31:08 +0100 Subject: [PATCH] Slightly optimize lists:enumerate/1,2 Only test that `Index` is an integer once, and not once for each list element. --- lib/stdlib/src/lists.erl | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/stdlib/src/lists.erl b/lib/stdlib/src/lists.erl index b2d2c33ea3..c429e15263 100644 --- a/lib/stdlib/src/lists.erl +++ b/lib/stdlib/src/lists.erl @@ -962,17 +962,20 @@ keymap(Fun, Index, []) when is_integer(Index), Index >= 1, List2 :: [{Index, T}], Index :: integer(), T :: term(). -enumerate(List1) -> - enumerate(1, List1). +enumerate(List1) when is_list(List1) -> + enumerate_1(1, List1). -spec enumerate(Index, List1) -> List2 when List1 :: [T], List2 :: [{Index, T}], Index :: integer(), T :: term(). -enumerate(Index, [H|T]) when is_integer(Index) -> - [{Index, H}|enumerate(Index + 1, T)]; -enumerate(Index, []) when is_integer(Index) -> +enumerate(Index, List1) when is_integer(Index), is_list(List1) -> + enumerate_1(Index, List1). + +enumerate_1(Index, [H|T]) -> + [{Index, H}|enumerate_1(Index + 1, T)]; +enumerate_1(_Index, []) -> []. %%% Suggestion from OTP-2948: sort and merge with Fun. -- 2.34.1
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor