Instead of iterating twice over the string, first for searching the
null-terminator and then to compare it to `name`, we only iterate
over it once.
Commit migrated from https://github.com/dotnet/coreclr/commit/
d606bff508cf57477b21ebbe8c8a2f6494feed7e
size_t nameLength = strlen(name);
for (int i = 0; palEnvironment[i] != nullptr; ++i)
{
- if (strlen(palEnvironment[i]) < nameLength)
- {
- continue;
- }
-
- if (memcmp(palEnvironment[i], name, nameLength) == 0)
+ if (strncmp(palEnvironment[i], name, nameLength) == 0)
{
char *equalsSignPosition = palEnvironment[i] + nameLength;