Skip to content

Commit

Permalink
perfomance boost with ip2addr
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielR92 committed Oct 19, 2024
1 parent 78cbd77 commit 6f9601c
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/utils/helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ const char dayShortNames_P[] PROGMEM = STR_DAYNAME_3_CHAR_LIST;

namespace ah {
void ip2Arr(uint8_t ip[], const char *ipStr) {
uint8_t p = 1;
memset(ip, 0, 4);
for(uint8_t i = 0; i < 16; i++) {
if(ipStr[i] == 0)
return;
if(0 == i)
ip[0] = atoi(ipStr);
else if(ipStr[i] == '.')
ip[p++] = atoi(&ipStr[i+1]);
uint8_t p = 0;
const char *start = ipStr;

for (uint8_t i = 0; i < 4; i++) {
ip[i] = (uint8_t)strtol(start, (char**)&start, 10);
if (*start == '.') {
start++;
} else if (*start == '\0') {
break;
}
}
}

Expand Down

0 comments on commit 6f9601c

Please sign in to comment.