Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] [gdb] Use std::swap
@ 2026-11-25 13:38 Tom de Vries
  2026-11-25 13:38 ` [PATCH 2/2] [gdb] Use std::exchange Tom de Vries
  0 siblings, 1 reply; 2+ messages in thread
From: Tom de Vries @ 2026-11-25 13:38 UTC (permalink / raw)
  To: gdb-patches

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-25 13:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-25 13:38 [PATCH 1/2] [gdb] Use std::swap Tom de Vries
2026-11-25 13:38 ` [PATCH 2/2] [gdb] Use std::exchange Tom de Vries

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox