diff options
author | Björn Gustavsson <[email protected]> | 2017-01-11 11:55:40 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2017-01-11 11:55:40 +0100 |
commit | b2b0fbdf447e04f794d4682baac96a4143a005da (patch) | |
tree | dd7a119e7544b12854c68825a896e7237aef1619 /system/doc/efficiency_guide/listhandling.xml | |
parent | 56a1d1ccf742e9a6eaf86d38f37ad79731e1b019 (diff) | |
parent | 947169af61bdd67d34fabd47a56be04e8468120d (diff) | |
download | otp-b2b0fbdf447e04f794d4682baac96a4143a005da.tar.gz otp-b2b0fbdf447e04f794d4682baac96a4143a005da.tar.bz2 otp-b2b0fbdf447e04f794d4682baac96a4143a005da.zip |
Merge pull request #1301 from bjorng/bjorn/efficiency-guide
Remove obsolete information from the Efficiency Guide
Diffstat (limited to 'system/doc/efficiency_guide/listhandling.xml')
-rw-r--r-- | system/doc/efficiency_guide/listhandling.xml | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/system/doc/efficiency_guide/listhandling.xml b/system/doc/efficiency_guide/listhandling.xml index 2ebc877820..ec258d7c2a 100644 --- a/system/doc/efficiency_guide/listhandling.xml +++ b/system/doc/efficiency_guide/listhandling.xml @@ -90,7 +90,7 @@ tail_recursive_fib(N, Current, Next, Fibs) -> <p>Lists comprehensions still have a reputation for being slow. They used to be implemented using funs, which used to be slow.</p> - <p>In recent Erlang/OTP releases (including R12B), a list comprehension:</p> + <p>A list comprehension:</p> <code type="erl"><![CDATA[ [Expr(E) || E <- List]]]></code> @@ -102,7 +102,7 @@ tail_recursive_fib(N, Current, Next, Fibs) -> [Expr(E)|'lc^0'(Tail, Expr)]; 'lc^0'([], _Expr) -> [].</code> - <p>In R12B, if the result of the list comprehension will <em>obviously</em> + <p>If the result of the list comprehension will <em>obviously</em> not be used, a list will not be constructed. For example, in this code:</p> <code type="erl"><![CDATA[ @@ -131,6 +131,14 @@ some_function(...), 'lc^0'(Tail, Expr); 'lc^0'([], _Expr) -> [].</code> + <p>The compiler also understands that assigning to '_' means that + the value will not used. Therefore, the code in the following example + will also be optimized:</p> + + <code type="erl"><![CDATA[ +_ = [io:put_chars(E) || E <- List], +ok.]]></code> + </section> <section> @@ -209,11 +217,11 @@ some_function(...), <section> <title>Recursive List Functions</title> - <p>In Section 7.2, the following myth was exposed: + <p>In section about myths, the following myth was exposed: <seealso marker="myths#tail_recursive">Tail-Recursive Functions are Much Faster Than Recursive Functions</seealso>.</p> - <p>To summarize, in R12B there is usually not much difference between + <p>There is usually not much difference between a body-recursive list function and tail-recursive function that reverses the list at the end. Therefore, concentrate on writing beautiful code and forget about the performance of your list functions. In the |