Update of /cvsroot/objecthandler/ObjectHandler/ohxl/Conversions
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv8402/ohxl/Conversions
Modified Files:
opertomatrix.hpp opertovector.hpp
Log Message:
"Use reserve to avoid unnecessary reallocations" -- Scott Mayers "Effective STL", item 14
Index: opertovector.hpp
===================================================================
RCS file: /cvsroot/objecthandler/ObjectHandler/ohxl/Conversions/opertovector.hpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** opertovector.hpp 19 Nov 2006 13:08:27 -0000 1.2
--- opertovector.hpp 2 Jan 2007 14:47:50 -0000 1.3
***************
*** 45,48 ****
--- 45,49 ----
}
+ ret.reserve(xMulti->val.array.rows * xMulti->val.array.columns);
for (int i=0; i<xMulti->val.array.rows * xMulti->val.array.columns; i++) {
T value;
***************
*** 67,71 ****
std::vector<T> fpToVector(const FP &fpVector) {
std::vector<T> ret;
! for (int i=0; i<fpVector.rows * fpVector.columns; i++)
ret.push_back(fpVector.array[i]);
return ret;
--- 68,73 ----
std::vector<T> fpToVector(const FP &fpVector) {
std::vector<T> ret;
! ret.reserve(fpVector.rows * fpVector.columns);
! for (int i=0; i<fpVector.rows * fpVector.columns; ++i)
ret.push_back(fpVector.array[i]);
return ret;
Index: opertomatrix.hpp
===================================================================
RCS file: /cvsroot/objecthandler/ObjectHandler/ohxl/Conversions/opertomatrix.hpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** opertomatrix.hpp 19 Nov 2006 13:08:27 -0000 1.2
--- opertomatrix.hpp 2 Jan 2007 14:47:50 -0000 1.3
***************
*** 45,50 ****
--- 45,52 ----
}
+ ret.reserve(xMulti->val.array.rows);
for (int i=0; i<xMulti->val.array.rows; i++) {
std::vector<T> row;
+ row.reserve(val.array.columns);
for (int j=0; j<xMulti->val.array.columns; j++) {
T value;
***************
*** 71,76 ****
--- 73,80 ----
std::vector<std::vector<T> > fpToMatrix(const FP &fpMatrix) {
std::vector<std::vector<T> > ret;
+ ret.reserve(fpMatrix.rows);
for (int i=0; i<fpMatrix.rows; i++) {
std::vector<T> row;
+ row.reserve(fpMatrix.columns);
for (int j=0; j<fpMatrix.columns; j++)
row.push_back(fpMatrix.array[i * fpMatrix.columns + j]);
|