Bug 1857841 - pt 3. Add a new page kind named "fresh" r=glandium
[gecko.git] / gfx / src / ArrayView.h
blobe5d5ace9761c195a5fea124d26ba3070e8e8208d
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef MOZILLA_GFX_ARRAY_VIEW_H_
7 #define MOZILLA_GFX_ARRAY_VIEW_H_
9 #include "nsTArray.h"
11 /* This is similar to mfbt/Range.h but has implicit conversion
12 * from nsTArray and less bounds checking.
13 * For now, prefer Range over ArrayView */
15 namespace mozilla {
16 namespace gfx {
18 template <typename T>
19 class ArrayView {
20 public:
21 MOZ_IMPLICIT ArrayView(const nsTArray<T>& aData)
22 : mData(aData.Elements()), mLength(aData.Length()) {}
23 ArrayView(const T* aData, const size_t aLength)
24 : mData(aData), mLength(aLength) {}
25 const T& operator[](const size_t aIdx) const { return mData[aIdx]; }
26 size_t Length() const { return mLength; }
27 const T* Data() const { return mData; }
29 private:
30 const T* mData;
31 const size_t mLength;
34 } // namespace gfx
35 } // namespace mozilla
37 #endif /* MOZILLA_GFX_ARRAY_VIEW_H_ */