public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* minor optimization bug in basic_string move assignment
@ 2023-01-03 23:11 waffl3x
  2023-01-04 18:20 ` François Dumont
  0 siblings, 1 reply; 7+ messages in thread
From: waffl3x @ 2023-01-03 23:11 UTC (permalink / raw)
  To: libstdc++

[-- Attachment #1: Type: text/plain, Size: 1051 bytes --]

Example: https://godbolt.org/z/sKhGqG1qK
https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=libstdc%2B%2B-v3/include/bits/basic_string.h;hb=HEAD#l880
When move assigning to a basic_string, the allocated memory of the moved into string is stored into the source string instead of deallocating it, a good optimization when everything is compatible. However in the case of a stateful allocator (is_always_true() evaluating as false) this optimization is never taken. Unless there is some reason I can't think of that makes equal stateful allocators incompatible here, I believe the if statement on line 880 of basic_string.h should also compare the equality of each strings allocator. The first condition in the function seems to indicate to me that this scenario was being considered and just forgotten about, as the memory doesn't get deallocated immediately if the two allocators are equal. I'll note that because of how everything is handled, this doesn't result in a leak so this bug is still only a minor missed optimization.

mailto:libstdc++@gcc.gnu.org

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

end of thread, other threads:[~2023-02-04 13:31 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-03 23:11 minor optimization bug in basic_string move assignment waffl3x
2023-01-04 18:20 ` François Dumont
2023-01-17 19:18   ` Jonathan Wakely
2023-01-25 18:38     ` [PATCH] " François Dumont
2023-02-03 14:50       ` Jonathan Wakely
2023-02-04 13:11         ` François Dumont
2023-02-04 13:30           ` 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).