From patchwork Thu Sep 21 19:42:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 76545 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8ACB73858C27 for ; Thu, 21 Sep 2023 19:42:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8ACB73858C27 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1695325362; bh=cyJFB66l0nysR7q/5sWninnCn6eS2SFGU1vrqR6KRmU=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=e5v0fpmvdaQGHKfIcm6YF2gRujaTVFwajcSjiYTuw3SHwccvR/Bhq3ZqM7jYjVU5D D4DgNPf/1BHcG3BXxcXqw9w6MPMs31RtK7uE77gBn5p1WNPU9jy0pftLn2aFk9EPHX 5gGi6FyLvd9HgJtnDeL3gXcgFAiDC0d4lgYxtOjQ= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd2a.google.com (mail-io1-xd2a.google.com [IPv6:2607:f8b0:4864:20::d2a]) by sourceware.org (Postfix) with ESMTPS id 0ECA43858D39 for ; Thu, 21 Sep 2023 19:42:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0ECA43858D39 Received: by mail-io1-xd2a.google.com with SMTP id ca18e2360f4ac-79545e141c7so40387339f.0 for ; Thu, 21 Sep 2023 12:42:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695325338; x=1695930138; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=cyJFB66l0nysR7q/5sWninnCn6eS2SFGU1vrqR6KRmU=; b=Sof8uk8oq9liM3hfbSQ3pYRzojif5LkON8DUcIgTIFo89g3yyTUvzCgKafK+Y9lU0L IUEiHbVG4g3VrWSmOyafTXr6+57CjNI0WuwJMfR+SVd9KBVfl9iTjruliWq1ZFa7AgBu jlAUkd834gy82yKmGtbcUrgy46zkMnp4BTMJel1Ckv445PZKLYw2o77/loYCXVBWXY9J s0qvRkerSWBoJMDmwV5ohzZ/9afWiZDnnhPRrJLNI61ML4VnMMfnw0ZstcWlzQdeET9Q cb6/LwwyxyC0pI04C7as4v95IsBYBV88zfUvUWTTpooHPfN85Lq7GODVFueRGjJZcwrZ zDHw== X-Gm-Message-State: AOJu0YxrdKlOAZ5R9wHSTwHEXyaG6ezk2KTWLY7ZVZ5DnrjHUg8o8zDJ Jq3CzMBmUWSDeocuydMuxDbL+KEJwxiuPpIR1bWYGw== X-Google-Smtp-Source: AGHT+IF2Xjwfzk8kEVEorgOBUEOzeolD/K+5gxn3Mrn3Dmx/pty3X6NxRu7LMQJ50Z+mV3BJA/W/ww== X-Received: by 2002:a05:6602:2251:b0:794:eb37:b0da with SMTP id o17-20020a056602225100b00794eb37b0damr524478ioo.2.1695325338281; Thu, 21 Sep 2023 12:42:18 -0700 (PDT) Received: from localhost.localdomain (71-211-130-31.hlrn.qwest.net. [71.211.130.31]) by smtp.gmail.com with ESMTPSA id m9-20020a6bea09000000b0077e40979b41sm499423ioc.45.2023.09.21.12.42.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 12:42:17 -0700 (PDT) To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Use string_file::release in some places Date: Thu, 21 Sep 2023 13:42:07 -0600 Message-Id: <20230921194207.2401885-1-tromey@adacore.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-Spam-Status: No, score=-11.6 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 autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" I found a few spots like: string_file f; std::string x = f.string (); However, string_file::string returns a 'const std::string &'... so it seems to me that this must be copying the string (? I find it hard to reason about this in C++). This patch changes these spots to use release() instead, which moves the string. Reviewed-by: Keith Seitz Reviewed-by: Lancelot Six --- gdb/breakpoint.c | 2 +- gdb/top.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index d807ae3c9b5..f9b20a7d62d 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -7581,7 +7581,7 @@ bp_location::to_string () const string_file stb; ui_out_redirect_pop redir (current_uiout, &stb); print_breakpoint_location (this->owner, this); - return stb.string (); + return stb.release (); } /* Decrement reference count. If the reference count reaches 0, diff --git a/gdb/top.c b/gdb/top.c index 2322e55f1db..cbe14b01046 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -647,12 +647,12 @@ execute_fn_to_string (std::string &res, std::function fn, catch (...) { /* Finally. */ - res = std::move (str_file.string ()); + res = str_file.release (); throw; } /* And finally. */ - res = std::move (str_file.string ()); + res = str_file.release (); } /* See gdbcmd.h. */