summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-04-09 17:45:54 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-04-09 17:45:54 +0000
commit269963f90fa882869c3a33c8c9ecba41351cb27d (patch)
treeb2e73bb87dc8b1b4fe51658495e0faafb086975a
parent1ee9601b01259b3e1b1a5b43801264ec6f5090c1 (diff)
downloadpdfium-269963f90fa882869c3a33c8c9ecba41351cb27d.tar.xz
Make pdfium::span<> be based off of UnownedPtr<>.
Because we can get the lifetime check for free if we do this. This requires adding some "constexpr/noexcept" to UnownedPtr to make the types line up with what span.h requires. Change-Id: I45918f8723122082036eed959f769644ab4c509f Reviewed-on: https://pdfium-review.googlesource.com/29672 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
-rw-r--r--core/fxcrt/unowned_ptr.h14
-rw-r--r--third_party/DEPS1
-rw-r--r--third_party/base/span.h15
3 files changed, 16 insertions, 14 deletions
diff --git a/core/fxcrt/unowned_ptr.h b/core/fxcrt/unowned_ptr.h
index b1c9c66b3e..0e3bf9e09b 100644
--- a/core/fxcrt/unowned_ptr.h
+++ b/core/fxcrt/unowned_ptr.h
@@ -40,25 +40,25 @@ namespace fxcrt {
template <class T>
class UnownedPtr {
public:
- UnownedPtr() = default;
- UnownedPtr(const UnownedPtr& that) : UnownedPtr(that.Get()) {}
+ constexpr UnownedPtr() noexcept = default;
+ constexpr UnownedPtr(const UnownedPtr& that) noexcept = default;
template <typename U>
- explicit UnownedPtr(U* pObj) : m_pObj(pObj) {}
+ explicit constexpr UnownedPtr(U* pObj) noexcept : m_pObj(pObj) {}
// Deliberately implicit to allow returning nullptrs.
// NOLINTNEXTLINE(runtime/explicit)
- UnownedPtr(std::nullptr_t ptr) {}
+ constexpr UnownedPtr(std::nullptr_t ptr) noexcept {}
~UnownedPtr() { ProbeForLowSeverityLifetimeIssue(); }
- UnownedPtr& operator=(T* that) {
+ UnownedPtr& operator=(T* that) noexcept {
ProbeForLowSeverityLifetimeIssue();
m_pObj = that;
return *this;
}
- UnownedPtr& operator=(const UnownedPtr& that) {
+ UnownedPtr& operator=(const UnownedPtr& that) noexcept {
ProbeForLowSeverityLifetimeIssue();
if (*this != that)
m_pObj = that.Get();
@@ -81,7 +81,7 @@ class UnownedPtr {
return !(*this == that);
}
- T* Get() const { return m_pObj; }
+ T* Get() const noexcept { return m_pObj; }
T* Release() {
ProbeForLowSeverityLifetimeIssue();
diff --git a/third_party/DEPS b/third_party/DEPS
index 93ca1a0bd4..392d0124c9 100644
--- a/third_party/DEPS
+++ b/third_party/DEPS
@@ -3,5 +3,6 @@ include_rules = [
'+core/fxcrt/fx_coordinates.h',
'+core/fxcrt/fx_memory.h',
'+core/fxcrt/fx_system.h',
+ '+core/fxcrt/unowned_ptr.h',
'+build',
]
diff --git a/third_party/base/span.h b/third_party/base/span.h
index d8d8f29e7c..034c6a35e7 100644
--- a/third_party/base/span.h
+++ b/third_party/base/span.h
@@ -13,6 +13,7 @@
#include <type_traits>
#include <utility>
+#include "core/fxcrt/unowned_ptr.h"
#include "third_party/base/logging.h"
namespace pdfium {
@@ -224,14 +225,14 @@ class span {
const span last(size_t count) const {
CHECK(count <= size_);
- return span(data_ + (size_ - count), count);
+ return span(data_.Get() + (size_ - count), count);
}
const span subspan(size_t pos, size_t count = -1) const {
const auto npos = static_cast<size_t>(-1);
CHECK(pos <= size_);
CHECK(count == npos || count <= size_ - pos);
- return span(data_ + pos, count == npos ? size_ - pos : count);
+ return span(data_.Get() + pos, count == npos ? size_ - pos : count);
}
// [span.obs], span observers
@@ -241,13 +242,13 @@ class span {
// [span.elem], span element access
const T& operator[](size_t index) const noexcept {
CHECK(index < size_);
- return data_[index];
+ return data_.Get()[index];
}
- constexpr T* data() const noexcept { return data_; }
+ constexpr T* data() const noexcept { return data_.Get(); }
// [span.iter], span iterator support
- constexpr iterator begin() const noexcept { return data_; }
- constexpr iterator end() const noexcept { return data_ + size_; }
+ constexpr iterator begin() const noexcept { return data_.Get(); }
+ constexpr iterator end() const noexcept { return data_.Get() + size_; }
constexpr const_iterator cbegin() const noexcept { return begin(); }
constexpr const_iterator cend() const noexcept { return end(); }
@@ -267,7 +268,7 @@ class span {
}
private:
- T* data_;
+ UnownedPtr<T> data_;
size_t size_;
};