Standard_Real NewU = U;
Handle(TColStd_HArray1OfReal) TheKnots;
if (WithKnotRepetition) TheKnots = flatknots;
else TheKnots = knots;
const TColStd_Array1OfReal & CKnots = TheKnots->Array1();
PeriodicNormalization(NewU); //Attention a la periode
Standard_Real UFirst = CKnots (1);
Standard_Real ULast = CKnots (CKnots.Length());
if (Abs (NewU - UFirst) <= Abs(ParametricTolerance)) { I1 = I2 = 1; }
else if (Abs (NewU - ULast) <= Abs(ParametricTolerance)) {
I1 = I2 = CKnots.Length();
}
else if (NewU < UFirst - Abs(ParametricTolerance)) {
I2 = 1;
I1 = 0;
}
else if (NewU > ULast + Abs(ParametricTolerance)) {
I1 = CKnots.Length();
I2 = I1 + 1;
}
else {
I1 = 1;
BSplCLib::Hunt (CKnots, NewU, I1);
while ( Abs( CKnots(I1+1) - NewU) <= Abs(ParametricTolerance)) I1++;
if ( Abs( CKnots(I1) - NewU) <= Abs(ParametricTolerance)) {
I2 = I1;
}
else {
I2 = I1 + 1;
}
}
带H的是Handle 操作允许数组的共享。
const TColStd_Array1OfReal & CKnots = TheKnots->Array1();
给出的一个安全代码。从以上看到,有时候效率并不是我们考虑的。在做好代码安全保障之前,和代码的逻辑正确。以上代码现代的编译器都可以做很好的优化?