[PPL-devel] [GIT] ppl/ppl(master): Avoid useless allocations by only adding recycled rows to Bit_Matrix.
Roberto Bagnara
bagnara at cs.unipr.it
Mon Apr 20 12:18:36 CEST 2009
Module: ppl/ppl
Branch: master
Commit: 73047e08667ebca99b0262dd03c07f100f3c2925
URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=73047e08667ebca99b0262dd03c07f100f3c2925
Author: Roberto Bagnara <bagnara at cs.unipr.it>
Date: Mon Apr 20 12:18:05 2009 +0200
Avoid useless allocations by only adding recycled rows to Bit_Matrix.
---
src/Bit_Matrix.cc | 9 +++++----
src/Bit_Matrix.defs.hh | 8 +++++++-
src/conversion.cc | 4 ++--
3 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/src/Bit_Matrix.cc b/src/Bit_Matrix.cc
index ac126c5..dbce634 100644
--- a/src/Bit_Matrix.cc
+++ b/src/Bit_Matrix.cc
@@ -55,7 +55,7 @@ PPL::Bit_Matrix::sort_rows() {
}
void
-PPL::Bit_Matrix::add_row(const Bit_Row& row) {
+PPL::Bit_Matrix::add_recycled_row(Bit_Row& row) {
const dimension_type new_rows_size = rows.size() + 1;
if (rows.capacity() < new_rows_size) {
// Reallocation will take place.
@@ -64,7 +64,7 @@ PPL::Bit_Matrix::add_row(const Bit_Row& row) {
new_rows.insert(new_rows.end(), new_rows_size, Bit_Row());
// Put the new row in place.
dimension_type i = new_rows_size-1;
- new_rows[i] = row;
+ new_rows[i].swap(row);
// Steal the old rows.
while (i-- > 0)
new_rows[i].swap(rows[i]);
@@ -72,8 +72,9 @@ PPL::Bit_Matrix::add_row(const Bit_Row& row) {
std::swap(rows, new_rows);
}
else
- // Reallocation will NOT take place: append a new empty row.
- rows.push_back(row);
+ // Reallocation will NOT take place: append an empty row
+ // and swap it with the new row.
+ rows.insert(rows.end(), Bit_Row())->swap(row);
assert(OK());
}
diff --git a/src/Bit_Matrix.defs.hh b/src/Bit_Matrix.defs.hh
index 82f4b4f..c460924 100644
--- a/src/Bit_Matrix.defs.hh
+++ b/src/Bit_Matrix.defs.hh
@@ -94,7 +94,13 @@ public:
bool sorted_contains(const Bit_Row& row) const;
//! Adds \p row to \p *this.
- void add_row(const Bit_Row& row);
+ /*!
+ \param row
+ The row whose implementation will be recycled.
+
+ The only thing that can be done with \p row upon return is destruction.
+ */
+ void add_recycled_row(Bit_Row& row);
//! Erases the rows from the \p first_to_erase -th to the last one.
void rows_erase_to_end(dimension_type first_to_erase);
diff --git a/src/conversion.cc b/src/conversion.cc
index ec581f7..7c0b04b 100644
--- a/src/conversion.cc
+++ b/src/conversion.cc
@@ -721,10 +721,10 @@ PPL::Polyhedron::conversion(Linear_System& source,
// Make room for one more row.
dest.add_pending_row(Linear_Row::Flags(dest.topology(),
Linear_Row::RAY_OR_POINT_OR_INEQUALITY));
- sat.add_row(new_satrow);
+ sat.add_recycled_row(new_satrow);
}
else
- sat[dest_num_rows] = new_satrow;
+ sat[dest_num_rows].swap(new_satrow);
Linear_Row& new_row = dest[dest_num_rows];
// The following fragment optimizes the computation of
More information about the PPL-devel
mailing list