From 15ffab06839ee9b2af6c977f312284b1a876ca9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steven=20Dee=20=28J=C5=8Dshin=29?= Date: Sat, 15 Jun 2024 22:07:34 -0700 Subject: [PATCH] Use std::swap in string MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The STL spec says that swap is located in the string_view header anyawy. Performance-wise this is a noop, but it’s slightly cleaner. --- ctl/string.h | 5 +---- ctl/string_view.h | 1 + 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/ctl/string.h b/ctl/string.h index 0656418a5..bde53773f 100644 --- a/ctl/string.h +++ b/ctl/string.h @@ -87,10 +87,7 @@ class string void swap(string& s) noexcept { - char tmp[__::string_size]; - __builtin_memcpy(tmp, blob, __::string_size); - __builtin_memcpy(blob, s.blob, __::string_size); - __builtin_memcpy(s.blob, tmp, __::string_size); + std::swap(blob, s.blob); } string(string&& s) noexcept diff --git a/ctl/string_view.h b/ctl/string_view.h index 518c955bd..5f71a5fb3 100644 --- a/ctl/string_view.h +++ b/ctl/string_view.h @@ -2,6 +2,7 @@ // vi: set et ft=cpp ts=4 sts=4 sw=4 fenc=utf-8 :vi #ifndef COSMOPOLITAN_CTL_STRINGVIEW_H_ #define COSMOPOLITAN_CTL_STRINGVIEW_H_ +#include <__utility/swap.h> namespace ctl {