Bug 1147766 - Part 1: Add a mozilla::RangedArray class, for fixed length arrays with a non-zero base index. r=waldo
☠☠ backed out by 12cf9fdc778f ☠ ☠
authorCameron McCormack <cam@mcc.id.au>
Sat, 23 May 2015 12:50:44 +1000
changeset 276035 5754455de8464328ac5a5db6751a067bcdd621ae
parent 276034 a9e49636a440d4d8255875f48afa16edb7254b33
child 276036 10d6fcd9a4e0bd8d201d7e184ee192a4c5fd786a
push id4932
push userjlund@mozilla.com
push dateMon, 10 Aug 2015 18:23:06 +0000
treeherdermozilla-beta@6dd5a4f5f745 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswaldo
bugs1147766
milestone41.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1147766 - Part 1: Add a mozilla::RangedArray class, for fixed length arrays with a non-zero base index. r=waldo
mfbt/RangedArray.h
mfbt/moz.build
new file mode 100644
--- /dev/null
+++ b/mfbt/RangedArray.h
@@ -0,0 +1,44 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+ * A compile-time constant-length array, with bounds-checking assertions -- but
+ * unlike mozilla::Array, with indexes biased by a constant.
+ *
+ * Thus where mozilla::Array<int, 3> is a three-element array indexed by [0, 3),
+ * mozilla::RangedArray<int, 8, 3> is a three-element array indexed by [8, 11).
+ */
+
+#ifndef mozilla_RangedArray_h
+#define mozilla_RangedArray_h
+
+#include "mozilla/Array.h"
+
+namespace mozilla {
+
+template<typename T, size_t MinIndex, size_t Length>
+class RangedArray
+{
+public:
+  T& operator[](size_t aIndex)
+  {
+    MOZ_ASSERT(aIndex >= MinIndex);
+    return mArr[aIndex - MinIndex];
+  }
+
+  const T& operator[](size_t aIndex) const
+  {
+    MOZ_ASSERT(aIndex >= MinIndex);
+    return mArr[aIndex - MinIndex];
+  }
+
+private:
+  Array<T, Length> mArr;
+};
+
+} // namespace mozilla
+
+#endif // mozilla_RangedArray_h
--- a/mfbt/moz.build
+++ b/mfbt/moz.build
@@ -54,16 +54,17 @@ EXPORTS.mozilla = [
     'MemoryReporting.h',
     'Move.h',
     'NullPtr.h',
     'NumericLimits.h',
     'Pair.h',
     'PodOperations.h',
     'Poison.h',
     'Range.h',
+    'RangedArray.h',
     'RangedPtr.h',
     'RefCountType.h',
     'ReentrancyGuard.h',
     'RefPtr.h',
     'ReverseIterator.h',
     'RollingMean.h',
     'Scoped.h',
     'SegmentedVector.h',