https://bugs.llvm.org/show_bug.cgi?id=45848

            Bug ID: 45848
           Summary: std::~unique_ptr is inefficient
           Product: libc++
           Version: unspecified
          Hardware: Macintosh
                OS: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: unassignedclangb...@nondot.org
          Reporter: jsba...@adobe.com
                CC: llvm-bugs@lists.llvm.org, mclow.li...@gmail.com

The dtor of unique_ptr is implemented in terms of reset (which defaults to a
set of a nullptr).
  ~unique_ptr() { reset(); }

This is inefficient as the effect is that the dtor modifies the address held by
its ptr
    __ptr_.first() = __p;
This causes address invalidation (and a related cacheline invalidation).

Since this is in the dtor, noone should read that value again.

~unique_ptr should be implemented in terms of the contained destructor only:
~unique_ptr() {
    const pointer ptr = __ptr_.first();
    if (ptr)
        __ptr_.second()(ptr);
}

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to