[PATCH] D43430: Omit nullptr check for sufficiently simple delete-expressions

Kim Gräsman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Feb 17 01:41:50 PST 2018


kimgr added a comment.

Peanut gallery observation: there was a discussion on the Boost list years and years ago where someone made the case that `if (x != nullptr) delete x;` was measurably faster than just calling `delete x;` I can't find it now, but I think it might have been in the context of their `checked_delete` library. Anyway, the reasoning was that with an external nullptr check, you'd pay for one comparison, but without it you'd always pay for a jump + a comparison. I suppose that only holds true for null pointers, for non-null pointers the extra check is just waste.

It looks to me like the compiler inserts an external null check, and you're now removing it in select cases, did I understand that right? I wonder if this could have negative effects for frequent deletion of nullptrs (e.g. a sometimes-allocated member of a heavily used value type).

That said, I'm not sure how valid the observation back then still is.


Repository:
  rC Clang

https://reviews.llvm.org/D43430





More information about the cfe-commits mailing list