Add DCHECKs to ArenaVector and ScopedArenaVector.
Implement dchecked_vector<> template that DCHECK()s element
access and insert()/emplace()/erase() positions. Change the
ArenaVector<> and ScopedArenaVector<> aliases to use the new
template instead of std::vector<>. Remove DCHECK()s that
have now become unnecessary from the Optimizing compiler.
Change-Id: Ib8506bd30d223f68f52bd4476c76d9991acacadc
diff --git a/compiler/dwarf/writer.h b/compiler/dwarf/writer.h
index e703aee..42c32c4 100644
--- a/compiler/dwarf/writer.h
+++ b/compiler/dwarf/writer.h
@@ -26,8 +26,10 @@
namespace dwarf {
// The base class for all DWARF writers.
-template<typename Allocator = std::allocator<uint8_t>>
+template <typename Vector = std::vector<uint8_t>>
class Writer {
+ static_assert(std::is_same<typename Vector::value_type, uint8_t>::value, "Invalid value type");
+
public:
void PushUint8(int value) {
DCHECK_GE(value, 0);
@@ -116,8 +118,9 @@
data_->insert(data_->end(), p, p + size);
}
- template<typename Allocator2>
- void PushData(const std::vector<uint8_t, Allocator2>* buffer) {
+ template<typename Vector2>
+ void PushData(const Vector2* buffer) {
+ static_assert(std::is_same<typename Vector2::value_type, uint8_t>::value, "Invalid value type");
data_->insert(data_->end(), buffer->begin(), buffer->end());
}
@@ -155,14 +158,14 @@
data_->resize(RoundUp(data_->size(), alignment), 0);
}
- const std::vector<uint8_t, Allocator>* data() const {
+ const Vector* data() const {
return data_;
}
- explicit Writer(std::vector<uint8_t, Allocator>* buffer) : data_(buffer) { }
+ explicit Writer(Vector* buffer) : data_(buffer) { }
private:
- std::vector<uint8_t, Allocator>* data_;
+ Vector* const data_;
DISALLOW_COPY_AND_ASSIGN(Writer);
};