diff options
author | Hans Bolinder <[email protected]> | 2019-02-18 08:17:12 +0100 |
---|---|---|
committer | Hans Bolinder <[email protected]> | 2019-02-18 08:17:12 +0100 |
commit | d6d2aa5933512977bce54013221bcd7b33765f0b (patch) | |
tree | 661659044e8d05498b5ab16f55b64b984c2774c5 /lib/stdlib/src/io_lib.erl | |
parent | 77cff6693158dc2ab20b798db9c124a2c82f5e2a (diff) | |
parent | 54cea392023ac207fbf03efb82c1abcfb468cf8b (diff) | |
download | otp-d6d2aa5933512977bce54013221bcd7b33765f0b.tar.gz otp-d6d2aa5933512977bce54013221bcd7b33765f0b.tar.bz2 otp-d6d2aa5933512977bce54013221bcd7b33765f0b.zip |
Merge branch 'hasse/stdlib/optimize_pretty_print/ERIERL-306/OTP-15573' into maint
* hasse/stdlib/optimize_pretty_print/ERIERL-306/OTP-15573:
Update primary bootstrap
stdlib: Optimize formatted printing of terms
Diffstat (limited to 'lib/stdlib/src/io_lib.erl')
-rw-r--r-- | lib/stdlib/src/io_lib.erl | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/stdlib/src/io_lib.erl b/lib/stdlib/src/io_lib.erl index 8223a52873..2b5a374cf2 100644 --- a/lib/stdlib/src/io_lib.erl +++ b/lib/stdlib/src/io_lib.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2018. All Rights Reserved. +%% Copyright Ericsson AB 1996-2019. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. @@ -87,6 +87,8 @@ -export([limit_term/2]). +-export([chars_length/1]). + -export_type([chars/0, latin1_string/0, continuation/0, fread_error/0, fread_item/0, format_spec/0, chars_limit/0]). @@ -1131,3 +1133,17 @@ test_limit_map_assoc(K, V, D) -> test_limit(V, D - 1). test_limit_bitstring(_, _) -> ok. + +-spec chars_length(chars()) -> non_neg_integer(). +%% Optimized for deep lists S such that deep_latin1_char_list(S) is +%% true. No binaries allowed! It is assumed that $\r is never followed +%% by $\n if S is an iolist() (string:length() assigns such a +%% sub-sequence length 1). +chars_length(S) -> + try + %% true = deep_latin1_char_list(S), + iolist_size(S) + catch + _:_ -> + string:length(S) + end. |