[libcxx-commits] [PATCH] D80057: [libc++][NFCI] Optimization to std::~unique_ptr

Zoe Carver via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue May 19 14:21:12 PDT 2020


zoecarver added a comment.

What if we did the check before modifying the pointer?

  ~unique_ptr() {
      pointer __tmp = __ptr_.first();
      if (!__tmp)
          return
      __ptr_.first() = __p;
      __ptr_.second()(__tmp);
  }

We only get a performance improvement when the pointer is null so, this should be just as fast. And it will prevent just as many UaFs.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80057/new/

https://reviews.llvm.org/D80057





More information about the libcxx-commits mailing list