Lunderberg commented on code in PR #16183:
URL: https://github.com/apache/tvm/pull/16183#discussion_r1409879423
##########
include/tvm/runtime/packed_func.h:
##########
@@ -1996,8 +2123,10 @@ inline TObjectRef TVMPODValue_::AsObjectRef() const {
<< "Expect a not null value of " << ContainerType::_type_key;
return TObjectRef(ObjectPtr<Object>(nullptr));
}
- // NOTE: the following code can be optimized by constant folding.
- if (std::is_base_of<NDArray::ContainerType, ContainerType>::value) {
+
+ // NOTE: The following code uses "if constexpr" wherever possible to
+ // minimize the number of runtime checks.
Review Comment:
Holy cow, yeah. Each step from C++03 partial template specialization, to
C++11 `std::enable_if`, to C++17 `if constexpr` brings such an improvement in
readability. It probably results in the same optimized binary at the end,
since the optimizer would (probably) DCE the constants, but this way the
compiler will yell at me if I accidentally insert a runtime value into the
condition.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]