From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH 1/2] [gdb] Use std::swap
Date: Wed, 25 Nov 2026 14:38:39 +0100 [thread overview]
Message-ID: <20261125133840.2120851-1-tdevries@suse.de> (raw)
Use std::swap in a few places to make code more readable and shorter,
replacing:
...
{
auto tmp = a;
a = b;
b = tmp;
}
...
with:
...
std::swap (a, b);
...
Tested on x86_64-linux.
---
gdb/gcore.c | 9 ++-------
gdb/prologue-value.c | 7 ++-----
2 files changed, 4 insertions(+), 12 deletions(-)
diff --git a/gdb/gcore.c b/gdb/gcore.c
index b88085ad78b..53cb67977a3 100644
--- a/gdb/gcore.c
+++ b/gdb/gcore.c
@@ -38,6 +38,7 @@
#include "gdbsupport/scope-exit.h"
#include "auxv.h"
#include "cli/cli-style.h"
+#include <utility>
/* To generate sparse cores, we look at the data to write in chunks of
this size when considering whether to skip the write. Only if we
@@ -248,13 +249,7 @@ derive_stack_segment (bfd_vma *bottom, bfd_vma *top)
/* Now canonicalize their order, so that BOTTOM is a lower address
(as opposed to a lower stack frame). */
if (*bottom > *top)
- {
- bfd_vma tmp_vma;
-
- tmp_vma = *top;
- *top = *bottom;
- *bottom = tmp_vma;
- }
+ std::swap (*top, *bottom);
return 1;
}
diff --git a/gdb/prologue-value.c b/gdb/prologue-value.c
index 00a62d466f7..31845124fe3 100644
--- a/gdb/prologue-value.c
+++ b/gdb/prologue-value.c
@@ -18,6 +18,7 @@
#include "prologue-value.h"
#include "regcache.h"
+#include <utility>
\f
/* Constructors. */
@@ -69,11 +70,7 @@ constant_last (pv_t *a, pv_t *b)
{
if (a->kind == pvk_constant
&& b->kind != pvk_constant)
- {
- pv_t temp = *a;
- *a = *b;
- *b = temp;
- }
+ std::swap (*a, *b);
}
base-commit: 147e60cae54d6db8b466265354e8ee6571a24841
--
2.51.0
next reply other threads:[~2026-11-25 13:39 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 13:38 Tom de Vries [this message]
2026-11-25 13:38 ` [PATCH 2/2] [gdb] Use std::exchange Tom de Vries
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261125133840.2120851-1-tdevries@suse.de \
--to=tdevries@suse.de \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox