tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ArrayView.h (1113B)


      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/. */
      5 
      6 #ifndef MOZILLA_GFX_ARRAY_VIEW_H_
      7 #define MOZILLA_GFX_ARRAY_VIEW_H_
      8 
      9 #include "nsTArray.h"
     10 
     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 */
     14 
     15 namespace mozilla {
     16 namespace gfx {
     17 
     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; }
     28 
     29 private:
     30  const T* mData;
     31  const size_t mLength;
     32 };
     33 
     34 }  // namespace gfx
     35 }  // namespace mozilla
     36 
     37 #endif /* MOZILLA_GFX_ARRAY_VIEW_H_ */