I can't help you with the inline C but if your string is null terminated you do not need the len variable at all. Just use
while (*data)
and the if statement could be avoided by writing
s = s + (*(data++)=='\n');
This exploits that the boolean expression returns 0 or 1.
Whether this is faster is to be benchmarked as it will depend on compiler and how the code is actually compiled.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
I can't help you with the inline C but if your string is null terminated you do not need the len variable at all. Just use
and the if statement could be avoided by writing
This exploits that the boolean expression returns 0 or 1.
Whether this is faster is to be benchmarked as it will depend on compiler and how the code is actually compiled.