From d16e322f0286e0b3fb204a724a4f1fa4b75e6f59 Mon Sep 17 00:00:00 2001 From: Herb Derby Date: Mon, 4 May 2020 14:05:22 -0400 Subject: [PATCH] Add subspan() to SkSpan Change-Id: I1ac2ec8cf22a96c50261ca3863edeb0ed3c24dd6 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/287579 Reviewed-by: Ben Wagner Commit-Queue: Herb Derby --- src/core/SkSpan.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/core/SkSpan.h b/src/core/SkSpan.h index 06d9201fce..96084926ee 100644 --- a/src/core/SkSpan.h +++ b/src/core/SkSpan.h @@ -50,6 +50,12 @@ public: if (postfixLen == 0) { return SkSpan{}; } return SkSpan{fPtr + (this->size() - postfixLen), postfixLen}; } + constexpr SkSpan subspan(size_t offset, size_t count) const { + SkASSERT(offset <= this->size()); + SkASSERT(count <= this->size - offset); + if (count == 0) { return SkSpan{}; } + return SkSpan{fPtr + offset, count}; + } private: T* fPtr;