In optical flow fusion (libraries\AP_NavEKF2\AP_NavEKF2_OptFlowFusion.cpp), Kalman gain is PH*/(HPH*+R). Since we already computed H, we can use it to calculate PH*. However, in the code below, it computes t22, t9, …again:

Kfusion[0] = -t62*(t22+P[0][1]*t9+P[0][5]*t100-P[0][4]*t101-P[0][2]*t102-P[0][3]*t103+P[0][8]*t104);

Why do we need to repeat the same calculation?

I understand we use Matlab to optimize H and K separately, but it does not take too much effort to optimize it further. Maybe my understanding is wrong?