Skip to content

Commit

Permalink
move strlen outside of for loop comparisons so it constant value (#1209)
Browse files Browse the repository at this point in the history
is not recalcuated every loop
  • Loading branch information
craiglink committed May 5, 2024
1 parent 629353e commit 41c02f9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion FluidNC/src/Machine/Axes.cpp
Expand Up @@ -287,7 +287,8 @@ namespace Machine {

bool Axes::namesToMask(const char* names, AxisMask& mask) {
bool retval = true;
for (int i = 0; i < strlen(names); i++) {
const auto lenNames = strlen(names);
for (int i = 0; i < lenNames; i++) {
char axisName = toupper(names[i]);
char* pos = index(_names, axisName);
if (!pos) {
Expand Down
7 changes: 4 additions & 3 deletions FluidNC/src/ProcessSettings.cpp
Expand Up @@ -423,7 +423,8 @@ static Error home_all(const char* value, WebUI::AuthenticationLevel auth_level,
// or a list of axis names like "XZ", which will home the X and Z axes simultaneously
if (value) {
int ndigits = 0;
for (int i = 0; i < strlen(value); i++) {
const auto lenValue = strlen(value);
for (int i = 0; i < lenValue; i++) {
char cycleName = value[i];
if (isdigit(cycleName)) {
if (!Machine::Homing::axis_mask_from_cycle(cycleName - '0')) {
Expand All @@ -434,11 +435,11 @@ static Error home_all(const char* value, WebUI::AuthenticationLevel auth_level,
}
}
if (ndigits) {
if (ndigits != strlen(value)) {
if (ndigits != lenValue) {
log_error("Invalid homing cycle list");
return Error::InvalidValue;
} else {
for (int i = 0; i < strlen(value); i++) {
for (int i = 0; i < lenValue; i++) {
char cycleName = value[i];
requestedAxes = Machine::Homing::axis_mask_from_cycle(cycleName - '0');
retval = home(requestedAxes);
Expand Down

0 comments on commit 41c02f9

Please sign in to comment.