Skip to content

Commit 8424010

Browse files
committed
add benchmark on MatSym
1 parent eded94d commit 8424010

File tree

1 file changed

+3
-10
lines changed
  • Sofa/framework/Type/src/sofa/type

1 file changed

+3
-10
lines changed

Sofa/framework/Type/src/sofa/type/MatSym.h

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,21 +112,14 @@ class MatSym : public VecNoInit<D * (D + 1) / 2, real>
112112
/// Write access to element (i,j).
113113
inline real& operator()(const int i, const int j)
114114
{
115-
if (i >= j)
116-
{
117-
return this->elems[(i * (i + 1)) / 2 + j];
118-
}
119-
return this->elems[(j * (j + 1)) / 2 + i];
115+
return const_cast<real&>(std::as_const(*this)(i, j));
120116
}
121117

122118
/// Read-only access to element (i,j).
123119
inline const real& operator()(const int i, const int j) const
124120
{
125-
if (i >= j)
126-
{
127-
return this->elems[(i * (i + 1)) / 2 + j];
128-
}
129-
return this->elems[(j * (j + 1)) / 2 + i];
121+
const auto [a, b] = std::minmax(i, j);
122+
return this->elems[(a * (a + 1)) / 2 + b];
130123
}
131124

132125
/// convert matrix to sym

0 commit comments

Comments
 (0)