Performance improvement in mlx_equal functions #66
Unanswered
Jeroenvh99
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In these functions,
`bool mlx_equal_image(void* lstcontent, void* value)
{
const mlx_image_t* lcontent = lstcontent;
const mlx_image_t* lvalue = value;
}
bool mlx_equal_inst(void* lstcontent, void* value)
{
const draw_queue_t* lcontent = lstcontent;
const mlx_image_t* lvalue = value;
}
you copy the arguments to const variables first and then compare them, I think the copying to const variables is to prevent the value of the arguments from changing suddenly, but since this is a comparison that won't happen anyway. Would it be slightly more performant to write it like this
bool mlx_equal_image(void* lstcontent, void* value){
return ((mlx_image_t *)lstcontent == (mlx_image_t *)value);
}
bool mlx_equal_inst(void* lstcontent, void* value)
{
return (((draw_queue_t *)lstcontent)->image == (mlx_image_t *)value);
}`?
I don't know how much computing power it takes to typecast these variables in comparison to copying them to a new variable. I do think it is a bit less resource intensive since you're not declaring another two variables each time you execute the function. I also do think the typecasting method is faster since typecasting is a compile-time operation, which means that the cast doesn't take any time at runtime, but I'm not really certain, @W2Wizard any ideas on this?
Beta Was this translation helpful? Give feedback.
All reactions