altos: Optimize ao_freq_to_set a bit
authorKeith Packard <keithp@keithp.com>
Wed, 28 Mar 2012 01:19:05 +0000 (18:19 -0700)
committerKeith Packard <keithp@keithp.com>
Wed, 28 Mar 2012 01:19:05 +0000 (18:19 -0700)
Reduces size from 327 bytes to 287 bytes

Signed-off-by: Keith Packard <keithp@keithp.com>
src/core/ao_freq.c

index 13bcb383e8914d04e38aa8a02fa6a3be2d7cbdeb..67b0b037bdcc9defd2b2bd44f38fe7e6aea4a0a0 100644 (file)
@@ -30,20 +30,18 @@ int32_t ao_freq_to_set(int32_t freq, int32_t cal) {
        uint8_t neg = 0;
        __pdata int32_t error = -434550 / 2;
 
-       freq -= 434550;
-       if (freq < 0) {
+       if ((freq -= 434550) < 0) {
                neg = 1;
                freq = -freq;
        }
        for (;;) {
-               if (freq == 0 && error <= 0)
-                       break;
                if (error > 0) {
                        error -= 434550;
                        set++;
                } else {
                        error += cal;
-                       freq--;
+                       if (--freq < 0)
+                               break;
                }
        }
        if (neg)