From ed19b2bdaa89e6f6ca03211a9fb21457e92e64ea Mon Sep 17 00:00:00 2001 From: Andrew Thompson Date: Mon, 3 Feb 2014 15:47:58 -0500 Subject: Use lists:keyfind in io_lib_pretty as it is faster As all the options to the pretty printer are 2-tuples, lists:keyfind/3 is faster replacement for proplists:get_value/3. --- lib/stdlib/src/io_lib_pretty.erl | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'lib/stdlib') diff --git a/lib/stdlib/src/io_lib_pretty.erl b/lib/stdlib/src/io_lib_pretty.erl index 7637ad7a3d..711d20de6e 100644 --- a/lib/stdlib/src/io_lib_pretty.erl +++ b/lib/stdlib/src/io_lib_pretty.erl @@ -64,13 +64,13 @@ print(Term) -> (term(), options()) -> chars(). print(Term, Options) when is_list(Options) -> - Col = proplists:get_value(column, Options, 1), - Ll = proplists:get_value(line_length, Options, 80), - D = proplists:get_value(depth, Options, -1), - M = proplists:get_value(max_chars, Options, -1), - RecDefFun = proplists:get_value(record_print_fun, Options, no_fun), - Encoding = proplists:get_value(encoding, Options, epp:default_encoding()), - Strings = proplists:get_value(strings, Options, true), + Col = get_option(column, Options, 1), + Ll = get_option(line_length, Options, 80), + D = get_option(depth, Options, -1), + M = get_option(max_chars, Options, -1), + RecDefFun = get_option(record_print_fun, Options, no_fun), + Encoding = get_option(encoding, Options, epp:default_encoding()), + Strings = get_option(strings, Options, true), print(Term, Col, Ll, D, M, RecDefFun, Encoding, Strings); print(Term, RecDefFun) -> print(Term, -1, RecDefFun). @@ -727,3 +727,10 @@ chars(C, N) when (N band 1) =:= 0 -> chars(C, N) -> S = chars(C, N bsr 1), [C, S | S]. + +get_option(Key, TupleList, Default) -> + case lists:keyfind(Key, 1, TupleList) of + false -> Default; + {Key, Value} -> Value; + _ -> Default + end. -- cgit v1.2.3