zhiqiang-hhhh commented on code in PR #32614:
URL: https://github.com/apache/doris/pull/32614#discussion_r1536591316


##########
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:
   > maybe we could always throw exception, not return nullptr.
   
   
https://github.com/apache/doris/blob/2c017399fbd109bb96ae09373f8dc46d8306e8a7/be/src/vec/columns/column_array.cpp#L513
   
   the users of `typeid_cast` sometimes relay on the nullptr as their control 
flow, exception has bad performance when it is used as control flow.
   



-- 
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