zclllyybb commented on code in PR #32614:
URL: https://github.com/apache/doris/pull/32614#discussion_r1536663881


##########
be/src/vec/common/typeid_cast.h:
##########
@@ -43,34 +43,20 @@
   */
 template <typename To, typename From>
     requires std::is_reference_v<To>
-To typeid_cast(From& from) {
-    try {
-        if (typeid(from) == typeid(To)) {
-            return static_cast<To>(from);
-        }
-    } catch (const std::exception& e) {
-        throw doris::Exception(doris::ErrorCode::BAD_CAST, e.what());
-    }
+To typeid_cast(From& from) noexcept(false) {
+    if ((typeid(From) == typeid(To)) || (typeid(from) == typeid(To))) return 
static_cast<To>(from);
 
     throw doris::Exception(doris::ErrorCode::BAD_CAST,
                            "Bad cast from type " + 
demangle(typeid(from).name()) + " to " +
                                    demangle(typeid(To).name()));
 }
 
 template <typename To, typename From>
-To typeid_cast(From* from) {
-#ifndef NDEBUG
-    try {
-        if (typeid(*from) == typeid(std::remove_pointer_t<To>)) {
-            return static_cast<To>(from);
-        }
-    } catch (const std::exception& e) {
-        throw doris::Exception(doris::ErrorCode::BAD_CAST, e.what());
-    }
-#else
-    if (typeid(*from) == typeid(std::remove_pointer_t<To>)) {
+    requires std::is_pointer_v<To>
+To typeid_cast(From* from) noexcept {
+    if ((typeid(From) == typeid(std::remove_pointer_t<To>)) ||
+        (from && typeid(*from) == typeid(std::remove_pointer_t<To>)))
         return static_cast<To>(from);

Review Comment:
   
不是的,我们抛异常是在入参为空指针的时候才会抛。以前的行为,如果typeid不同,就是返回空指针。因为现在这个新写法应该不会带来更多的风险,应该是靠谱的。空指针的话肯定是代码有错才会出,这种情况下前、后的使用肯定会出问题,不必在这里处理成异常的。



-- 
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: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to