From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 6A1613858C83; Fri, 14 Oct 2022 14:35:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6A1613858C83 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1665758150; bh=r+1TDmqMRWhve0e62qGMg9AVz27SrAXynDWkfuPe6w4=; h=From:To:Subject:Date:From; b=ysq/9Qjq+IMMfldOU2yEZ/rRr9Lxcrx2YfrwG1WwH06T7lMuTXRCb6b/hoaPyWd41 vvjiTgzR2obzFTuRkHefzfQLvcAbpi5paGNUu9pYK2KhxgUdCxZTxHBc9Ai+mcow7b IAlAx9BYpZQz/vvEzhU3DTqExZYIwsehYs5+quzM= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r13-3303] libstdc++: Simplify print_raw function for debug assertions X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: 823e9097f70eb95ef09fde357aebd071aec311d9 X-Git-Newrev: cf0b7e9787c3686c47219a725f2cbcaa19faaaca Message-Id: <20221014143550.6A1613858C83@sourceware.org> Date: Fri, 14 Oct 2022 14:35:50 +0000 (GMT) List-Id: https://gcc.gnu.org/g:cf0b7e9787c3686c47219a725f2cbcaa19faaaca commit r13-3303-gcf0b7e9787c3686c47219a725f2cbcaa19faaaca Author: Jonathan Wakely Date: Wed Oct 12 11:59:33 2022 +0100 libstdc++: Simplify print_raw function for debug assertions Replace two uses of print_raw where it's clearer to just use fprintf directly. Then the only remaining use of print_raw is as the print_func argument of pretty_print. When called by pretty_print the count is either a positive integer or -1, so we can simplify print_raw itself. Remove the default argument, because it's never used. Remove the check for nbc == 0, which never happens (but would be harmless if it did). Replace the conditional expression with a single call to fprintf, using INT_MAX as the maximum length. libstdc++-v3/ChangeLog: * src/c++11/debug.cc (print_raw): Simplify. (print_word): Print indentation by calling fprintf directly. (_Error_formatter::_M_error): Print unindented string by calling fprintf directly. Diff: --- libstdc++-v3/src/c++11/debug.cc | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/libstdc++-v3/src/c++11/debug.cc b/libstdc++-v3/src/c++11/debug.cc index abc4124c01e..f2b25fbefce 100644 --- a/libstdc++-v3/src/c++11/debug.cc +++ b/libstdc++-v3/src/c++11/debug.cc @@ -37,6 +37,7 @@ #include // for std::abort #include // for std::isspace. #include // for std::strstr. +#include // for INT_MAX #include // for std::min. @@ -609,14 +610,11 @@ namespace { print_word(ctx, word, Length - 1); } void - print_raw(PrintContext& ctx, const char* str, ptrdiff_t nbc = -1) + print_raw(PrintContext& ctx, const char* str, ptrdiff_t nbc) { - if (nbc != 0) - { - ctx._M_column += (nbc > 0) - ? fprintf(stderr, "%.*s", (int)nbc, str) - : fprintf(stderr, "%s", str); - } + if (nbc == -1) + nbc = INT_MAX; + ctx._M_column += fprintf(stderr, "%.*s", (int)nbc, str); } void @@ -645,12 +643,9 @@ namespace || (ctx._M_column + visual_length < ctx._M_max_length) || (visual_length >= ctx._M_max_length && ctx._M_column == 1)) { - // If this isn't the first line, indent + // If this isn't the first line, indent. if (ctx._M_column == 1 && !ctx._M_first_line) - { - const char spacing[PrintContext::_S_indent + 1] = " "; - print_raw(ctx, spacing, PrintContext::_S_indent); - } + ctx._M_column += fprintf(stderr, "%*c", PrintContext::_S_indent, ' '); int written = fprintf(stderr, "%.*s", (int)length, word); @@ -1166,7 +1161,7 @@ namespace __gnu_debug PrintContext ctx; if (_M_file) { - print_raw(ctx, _M_file); + ctx._M_column += fprintf(stderr, "%s", _M_file); print_literal(ctx, ":"); go_to_next_line = true; }