Messages in this thread Patch in this message | | | From | Justin Madru <> | Subject | [PATCH] staging: s5k3e2fx.c: reduce complexity by factoring | Date | Sat, 5 Dec 2009 18:03:20 -0800 |
| |
I was style fixing some code when I ran into this code. It seems like the code could be reduced, by factoring the expression. But this results in a very simple expression.
Am I assuming something wrong? Or is this a bug in the original code? This doesn't look right because the assignment of s_move[i] has no mention of the loop counter.
Justin
------
the code was looping, seting s_move[i] to the following calculations
if (actual_step >= 0) s_move[i] = ((((i + 1) * gain + 0x200) - (i * gain + 0x200)) / 0x400); else s_move[i] = ((((i + 1) * gain - 0x200) - (i * gain - 0x200)) / 0x400);
but, by factoring the expression, it can be shown that they both reduce to a very simple expression:
s_move[i] = gain / 0x400;
Signed-off-by: Justin Madru <jdm64@gawab.com> --- drivers/staging/dream/camera/s5k3e2fx.c | 10 +++------- 1 files changed, 3 insertions(+), 7 deletions(-)
diff --git a/drivers/staging/dream/camera/s5k3e2fx.c b/drivers/staging/dream/camera/s5k3e2fx.c index f0e49be..d205a2d 100644 --- a/drivers/staging/dream/camera/s5k3e2fx.c +++ b/drivers/staging/dream/camera/s5k3e2fx.c @@ -1092,14 +1092,10 @@ static int32_t s5k3e2fx_move_focus(int direction, int32_t num_steps) actual_step = step_direction * (int16_t)num_steps; pos_offset = init_code + s5k3e2fx_ctrl->curr_lens_pos; - gain = actual_step * 0x400 / 5; + gain = actual_step / 5; - for (i = 0; i <= 4; i++) { - if (actual_step >= 0) - s_move[i] = ((((i+1)*gain+0x200) - (i*gain+0x200))/0x400); - else - s_move[i] = ((((i+1)*gain-0x200) - (i*gain-0x200))/0x400); - } + for (i = 0; i <= 4; i++) + s_move[i] = gain; /* Ring Damping Code */ for (i = 0; i <= 4; i++) { -- 1.6.5.4
| |