diff options
author | Hans Bolinder <[email protected]> | 2019-02-18 08:29:24 +0100 |
---|---|---|
committer | Hans Bolinder <[email protected]> | 2019-02-18 08:29:24 +0100 |
commit | 45c2c2bb6b5ad7307155c97773a7b9b24f6ba486 (patch) | |
tree | f701ef97762b5e0ed37d03cecbc5503f583ca977 /lib/stdlib/src/io_lib.erl | |
parent | 76da23bb4e06d62d91150e5c61a8deb37ff12e8f (diff) | |
parent | d6d2aa5933512977bce54013221bcd7b33765f0b (diff) | |
download | otp-45c2c2bb6b5ad7307155c97773a7b9b24f6ba486.tar.gz otp-45c2c2bb6b5ad7307155c97773a7b9b24f6ba486.tar.bz2 otp-45c2c2bb6b5ad7307155c97773a7b9b24f6ba486.zip |
Merge branch 'maint'
* maint:
Update primary bootstrap
stdlib: Optimize formatted printing of terms
Conflicts:
bootstrap/lib/stdlib/ebin/io_lib.beam
bootstrap/lib/stdlib/ebin/io_lib_format.beam
bootstrap/lib/stdlib/ebin/io_lib_pretty.beam
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. |