Is a C++ compiler capable of optimizing away the redundant nullptr comparison in the following code example (control != nullptr)? More specifically, can the compiler do this after it has inlined the segment of code marked with '//part 2'?
Please note that the code within the second if statement, in the following code example, will be moved out to an inline function located in the same class, in the same header file (mostly for the purposes of avoiding code duplication).
shared_ptr(weak_ptr<T>&& that) : pointer(that.pointer),
control(that.control)
{
// part 1
if (control != nullptr) { control->decrement_count_weak(); }
// part 2 (will be moved out to another inline marked function)
// increment_or_reset();
if (control != nullptr)
{
if (control->shared != 0) { control->increment_count_shared(); }
else { reset(); }
}
// part 3
that.pointer = nullptr; that.control = nullptr;
}
Aucun commentaire:
Enregistrer un commentaire