public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* [committed] libstdc++: Add comment to gslice::operator=(const gslice&) [PR100147]
@ 2024-02-08 21:49 Jonathan Wakely
  0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2024-02-08 21:49 UTC (permalink / raw)
  To: libstdc++, gcc-patches

Tested aarch64-linux. Pushed to trunk.

-- >8 --

There's no need to check for self-assignment here, it would just add
extra code for an unlikely case. Add a comment saying so.

libstdc++-v3/ChangeLog:

	PR libstdc++/100147
	* include/bits/gslice.h (operator=): Add comment about lack of
	self-assignment check.
---
 libstdc++-v3/include/bits/gslice.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libstdc++-v3/include/bits/gslice.h b/libstdc++-v3/include/bits/gslice.h
index 3d78da2bd75..d9a8b929a57 100644
--- a/libstdc++-v3/include/bits/gslice.h
+++ b/libstdc++-v3/include/bits/gslice.h
@@ -169,6 +169,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   inline gslice&
   gslice::operator=(const gslice& __g)
   {
+    // Safe for self-assignment. Checking for it would add overhead just to
+    // optimize a case that should never happen anyway.
     if (__g._M_index)
       __g._M_index->_M_increment_use();
     if (_M_index && _M_index->_M_decrement_use() == 0)
-- 
2.43.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-02-08 21:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-08 21:49 [committed] libstdc++: Add comment to gslice::operator=(const gslice&) [PR100147] Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).