From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io1-xd2f.google.com (mail-io1-xd2f.google.com [IPv6:2607:f8b0:4864:20::d2f]) by sourceware.org (Postfix) with ESMTPS id 2DDAB3858C74 for ; Mon, 28 Feb 2022 18:33:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2DDAB3858C74 Received: by mail-io1-xd2f.google.com with SMTP id t11so15715411ioi.7 for ; Mon, 28 Feb 2022 10:33:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IWOmGy2NNi0E3SlBPGMtQ/hoWlFCuBWOj24yangOjJo=; b=oovwsUNNx+4WlGGjZf+g3l0+JBHd9kiiazCT0snFv9IWMFfYImJjidgRTuVnGNB68z CtFSUpaR24nvxIOh616Bv9RWdkE8DN4ZggRQmapwzPZFadedf4wZvWeJtVnhH9CdGYre T9MChIwy4UcT7ryiSqnr2IefDNprXZveIvIXjDEbpATtmEHXREP2xstemTK7UI3FfNRF BAXy/sviGmVicHjNGhtUTxEoobvxAlaC/geDR/1ImROCGW9OxrUtPnN78sQUEPHBlFPT BC1dRhrqh2f3aXhIXKD2ujzHmhrAuIB8e7e5qQHeO3L27x1CnTkAUp9jp5k7dCh5xQr4 NE9w== X-Gm-Message-State: AOAM532q38SsRBIQtJEZrwrLyey3+6q2VgdIwZkXJUgv+gKmHTVQhxOe SxuM3nPzlAomMOKJa1uzQHIAVctXFwqKcQ== X-Google-Smtp-Source: ABdhPJyFtd7ty5J3sQ3XgmLmDOhFDM6E3UYycfLyAxctInth0MOo0fdTWc8SmVqAWGoErlH+RwtAWA== X-Received: by 2002:a5e:c648:0:b0:640:bc31:cbec with SMTP id s8-20020a5ec648000000b00640bc31cbecmr16109561ioo.79.1646073188548; Mon, 28 Feb 2022 10:33:08 -0800 (PST) Received: from murgatroyd.Home (75-166-141-253.hlrn.qwest.net. [75.166.141.253]) by smtp.gmail.com with ESMTPSA id h9-20020a92c089000000b002b8b3ce939fsm6558845ile.9.2022.02.28.10.33.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 10:33:08 -0800 (PST) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 2/5] Don't pre-size result string in ada_decode Date: Mon, 28 Feb 2022 11:33:01 -0700 Message-Id: <20220228183304.1162089-3-tromey@adacore.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220228183304.1162089-1-tromey@adacore.com> References: <20220228183304.1162089-1-tromey@adacore.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Feb 2022 18:33:10 -0000 Currently, ada_decode pre-sizes the output string, filling it with 'X' characters. However, it's a bit simpler and more flexible to let std::string do the work here, and simply append characters to the string as we go. This turns out to be useful for a subsequent patch. --- gdb/ada-lang.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index d44b0906e6d..9a7ab72f0e5 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -1004,7 +1004,7 @@ remove_compiler_suffix (const char *encoded, int *len) std::string ada_decode (const char *encoded, bool wrap) { - int i, j; + int i; int len0; const char *p; int at_start_name; @@ -1068,10 +1068,6 @@ ada_decode (const char *encoded, bool wrap) if (len0 > 1 && startswith (encoded + len0 - 1, "B")) len0 -= 1; - /* Make decoded big enough for possible expansion by operator name. */ - - decoded.resize (2 * len0 + 1, 'X'); - /* Remove trailing __{digit}+ or trailing ${digit}+. */ if (len0 > 1 && isdigit (encoded[len0 - 1])) @@ -1089,8 +1085,8 @@ ada_decode (const char *encoded, bool wrap) /* The first few characters that are not alphabetic are not part of any encoding we use, so we can copy them over verbatim. */ - for (i = 0, j = 0; i < len0 && !isalpha (encoded[i]); i += 1, j += 1) - decoded[j] = encoded[i]; + for (i = 0; i < len0 && !isalpha (encoded[i]); i += 1) + decoded.push_back (encoded[i]); at_start_name = 1; while (i < len0) @@ -1107,10 +1103,9 @@ ada_decode (const char *encoded, bool wrap) op_len - 1) == 0) && !isalnum (encoded[i + op_len])) { - strcpy (&decoded.front() + j, ada_opname_table[k].decoded); + decoded.append (ada_opname_table[k].decoded); at_start_name = 0; i += op_len; - j += strlen (ada_opname_table[k].decoded); break; } } @@ -1214,21 +1209,18 @@ ada_decode (const char *encoded, bool wrap) else if (i < len0 - 2 && encoded[i] == '_' && encoded[i + 1] == '_') { /* Replace '__' by '.'. */ - decoded[j] = '.'; + decoded.push_back ('.'); at_start_name = 1; i += 2; - j += 1; } else { /* It's a character part of the decoded name, so just copy it over. */ - decoded[j] = encoded[i]; + decoded.push_back (encoded[i]); i += 1; - j += 1; } } - decoded.resize (j); /* Decoded names should never contain any uppercase character. Double-check this, and abort the decoding if we find one. */ -- 2.31.1