util/nvmutil: further optimise swap command

don't swap pointers at all. handle it in the for loop.

258 sloccount now, versus 261.

Signed-off-by: Leah Rowe <leah@libreboot.org>
btrfsvols
Leah Rowe 2023-09-19 16:05:34 +01:00
parent 5e8013601a
commit d9bed11501
1 changed files with 5 additions and 8 deletions

View File

@ -279,15 +279,12 @@ void
writeGbeFile(void)
{
errno = 0;
if (cmd == writeGbeFile) {
err_if(!(validChecksum(0) || validChecksum(1)));
xorswap(gbe[0], gbe[1]);
}
for (int p = 0; p < 2; p++) {
if ((!nvmPartModified[p]) && (gbe[0] <= gbe[1]))
err_if((cmd == writeGbeFile) && !(validChecksum(0) || validChecksum(1)));
for (int p = 0, x = (cmd == writeGbeFile) ? 1 : 0; p < 2; p++) {
if ((!nvmPartModified[p]) && (cmd != writeGbeFile))
continue;
handle_endianness(p);
err_if(pwrite(fd, (uint8_t *) gbe[p], nf, p << 12) == -1);
handle_endianness(p^x);
err_if(pwrite(fd, (uint8_t *) gbe[p^x], nf, p << 12) == -1);
}
err_if(close(fd) == -1);
}