summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2014-11-12 11:27:07 -0500
committerMathias Stearn <mathias@10gen.com>2014-11-18 14:32:09 -0500
commita6bba2cd699581aa610c636cd25042f2b45c8093 (patch)
tree7b1041da8276c74c4467000bfb2566428154e5d7 /src
parentdebe7c741f6f21587003fc3be4ccda5147b7e27b (diff)
downloadmongo-a6bba2cd699581aa610c636cd25042f2b45c8093.tar.gz
Use OwnedPointerVector to track Changes
Saves one new/delete pair per change registration.
Diffstat (limited to 'src')
-rw-r--r--src/mongo/base/owned_pointer_vector.h16
-rw-r--r--src/mongo/db/storage/mmap_v1/dur_recovery_unit.cpp4
-rw-r--r--src/mongo/db/storage/mmap_v1/dur_recovery_unit.h5
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp6
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h5
5 files changed, 23 insertions, 13 deletions
diff --git a/src/mongo/base/owned_pointer_vector.h b/src/mongo/base/owned_pointer_vector.h
index 754e702941e..fb5ddc09554 100644
--- a/src/mongo/base/owned_pointer_vector.h
+++ b/src/mongo/base/owned_pointer_vector.h
@@ -94,8 +94,14 @@ namespace mongo {
*/
void erase(const_iterator it) {
delete *it;
- // vector::erase(const_iterator) is new in c++11, so converting to non-const iterator.
- _vector.erase(_vector.begin() + (it - begin()));
+ _vector.erase(toNonConstIter(it));
+ }
+
+ void erase(const_iterator begin, const_iterator end) {
+ for (const_iterator it = begin; it != end; ++it) {
+ delete *it;
+ }
+ _vector.erase(toNonConstIter(begin), toNonConstIter(end));
}
//
@@ -136,6 +142,12 @@ namespace mongo {
}
private:
+ typename std::vector<T*>::iterator toNonConstIter(const_iterator it) {
+ // This is needed for a few cases where c++03 vectors require non-const iterators that
+ // were relaxed in c++11 to allow const_iterators. It can go away when we require c++11.
+ return _vector.begin() + (it - begin());
+ }
+
std::vector<T*> _vector;
};
diff --git a/src/mongo/db/storage/mmap_v1/dur_recovery_unit.cpp b/src/mongo/db/storage/mmap_v1/dur_recovery_unit.cpp
index fe32dcb3c3a..f02392987f2 100644
--- a/src/mongo/db/storage/mmap_v1/dur_recovery_unit.cpp
+++ b/src/mongo/db/storage/mmap_v1/dur_recovery_unit.cpp
@@ -99,7 +99,7 @@ namespace mongo {
if (getDur().isDurable())
pushChangesToDurSubSystem();
- for (Changes::iterator it = _changes.begin(), end = _changes.end(); it != end; ++it) {
+ for (Changes::const_iterator it = _changes.begin(), end = _changes.end(); it != end; ++it) {
(*it)->commit();
}
@@ -202,7 +202,7 @@ namespace mongo {
void DurRecoveryUnit::registerChange(Change* change) {
invariant(inAUnitOfWork());
- _changes.push_back(ChangePtr(change));
+ _changes.push_back(change);
}
} // namespace mongo
diff --git a/src/mongo/db/storage/mmap_v1/dur_recovery_unit.h b/src/mongo/db/storage/mmap_v1/dur_recovery_unit.h
index 0d07fd38c9b..337d4542afa 100644
--- a/src/mongo/db/storage/mmap_v1/dur_recovery_unit.h
+++ b/src/mongo/db/storage/mmap_v1/dur_recovery_unit.h
@@ -26,9 +26,9 @@
* it in the license file.
*/
-#include <boost/shared_ptr.hpp>
#include <vector>
+#include "mongo/base/owned_pointer_vector.h"
#include "mongo/db/storage/recovery_unit.h"
#include "mongo/platform/compiler.h"
@@ -81,8 +81,7 @@ namespace mongo {
OperationContext* _txn;
// Changes are ordered from oldest to newest.
- typedef boost::shared_ptr<Change> ChangePtr;
- typedef std::vector<ChangePtr> Changes;
+ typedef OwnedPointerVector<Change> Changes;
Changes _changes;
// These are memory writes inside the mmapv1 mmaped files. Writes are ordered from oldest to
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp
index 69bd4300bb6..114e8afb611 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp
@@ -105,7 +105,7 @@ namespace mongo {
_txnClose( true );
}
- for (Changes::iterator it = _changes.begin(), end = _changes.end(); it != end; ++it) {
+ for (Changes::const_iterator it = _changes.begin(), end = _changes.end(); it != end; ++it) {
(*it)->commit();
}
_changes.clear();
@@ -116,7 +116,7 @@ namespace mongo {
_txnClose( false );
}
- for (Changes::reverse_iterator it = _changes.rbegin(), end = _changes.rend();
+ for (Changes::const_reverse_iterator it = _changes.rbegin(), end = _changes.rend();
it != end; ++it) {
(*it)->rollback();
}
@@ -162,7 +162,7 @@ namespace mongo {
void WiredTigerRecoveryUnit::registerChange(Change* change) {
invariant(_depth > 0);
- _changes.push_back(ChangePtr(change));
+ _changes.push_back(change);
}
WiredTigerRecoveryUnit* WiredTigerRecoveryUnit::get(OperationContext *txn) {
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h
index 27adc7502d7..462e53ca2f2 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h
@@ -35,8 +35,8 @@
#include <memory.h>
#include <boost/scoped_ptr.hpp>
-#include <boost/shared_ptr.hpp>
+#include "mongo/base/owned_pointer_vector.h"
#include "mongo/db/diskloc.h"
#include "mongo/db/operation_context.h"
#include "mongo/db/storage/recovery_unit.h"
@@ -109,8 +109,7 @@ namespace mongo {
bool _syncing;
DiskLoc _oplogReadTill;
- typedef boost::shared_ptr<Change> ChangePtr;
- typedef std::vector<ChangePtr> Changes;
+ typedef OwnedPointerVector<Change> Changes;
Changes _changes;
};