summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrank Buss <[email protected]>2022-09-25 01:49:26 +0200
committerMan, Jianting (Meco) <[email protected]>2022-10-08 22:37:41 -0400
commite80facfd06ec70340a779b9edfb367f79a0ecbc4 (patch)
tree33b7166df7489bf757117e915d6ade8185ec7b74
parent6b60aab136c19e4febfd8ebc9ecbff25c4672bb4 (diff)
remove unused code to improve speed
The RT_ASSERT(obj != object) line is only compiled for debug mode. But the rt_enter/exit_critical causes the compiler not to optimize at least these 2 calls, even if it could optimize out the whole loop, because the rt_list_entry function has no side effect, and RT_ASSET is a no-operation in release mode. So this patch fixes this: - no warnings anymore - better speed in release mode
-rw-r--r--src/object.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/object.c b/src/object.c
index af13731e21..cb177edbe6 100644
--- a/src/object.c
+++ b/src/object.c
@@ -331,7 +331,9 @@ void rt_object_init(struct rt_object *object,
const char *name)
{
rt_base_t level;
+#ifdef RT_DEBUG
struct rt_list_node *node = RT_NULL;
+#endif
struct rt_object_information *information;
#ifdef RT_USING_MODULE
struct rt_dlmodule *module = dlmodule_self();
@@ -341,6 +343,7 @@ void rt_object_init(struct rt_object *object,
information = rt_object_get_information(type);
RT_ASSERT(information != RT_NULL);
+#ifdef RT_DEBUG
/* check object type to avoid re-initialization */
/* enter critical */
@@ -353,13 +356,11 @@ void rt_object_init(struct rt_object *object,
struct rt_object *obj;
obj = rt_list_entry(node, struct rt_object, list);
- if (obj) /* skip warning when disable debug */
- {
- RT_ASSERT(obj != object);
- }
+ RT_ASSERT(obj != object);
}
/* leave critical */
rt_exit_critical();
+#endif
/* initialize object's parameters */
/* set object type to static */