Closed dstroy0 closed 2 years ago
Most of the overhead is going to be in readCommandFromBuffer and associated helper functions. The max number of data pointers is determined in begin(), and the type match flag array is allocated there as well instead of every iteration of readCommandFromBuffer.
I've been through all the helper functions and public methods that readCommandFromBuffer touches and condensed local parameters into objects that make sense and pass them by reference wherever possible.
the maximum number of parameters passed to a function is now 5, _calcCmdMemcmpRanges is only iterated over inside of addCommand, I think that is acceptable. Internally I tried to limit it to two or three parameters and pass by reference. Having structs like that makes it easier to compare and see if I am duplicating something already there.
Do you have any suggestions? I think I've found everything obvious.
Based on the issue title, I think you could make use of macro functions.
#define rf24_max(a, b) (a > b ? a : b)
But, I'm not sure if this is the best suggestion...
inline static
functionsconst
parameter values or anything known at compile time)disclaimer: I'm not well trained in C - I know C++ better than C.
I'll look for candidates to turn into function-like macros. Great suggestion. If you see anything let me know.
I think it's a great suggestion because we're doing a ton of repetitive things here and function like macros will probably end up being the fewest total instructions, so it will likely increase performance if we can implement them for even a few things.
Like maybe for a fake iterator like Linux Kernel does?
#define list_for_each_safe(pos, n, head) \
for (pos = (head)->next, n = pos->next; pos != (head); \
pos = n, n = pos->next)
That might be good.
If I do some iterators and it either increases speed or decreases pgm space I'll consider it a win.
I'm still working on this but it's on the back burner.
Compute static equations at runtime once instead of n times, assign result to private class member.
Reduce unnecessary overhead.