Bug 1592307: Part 9: SmallVector r=mgaudet
authorIain Ireland <iireland@mozilla.com>
Wed, 11 Dec 2019 20:40:55 +0000
changeset 506578 dfdef83bf5aa1d833fd0a598ad4c834bbe280e4b
parent 506577 5adb89d54f128b77d4a60815af2a36339a15d7e8
child 506579 8d8524404286679a1d6962abbf16c86a0a58536b
push id36908
push usermalexandru@mozilla.com
push dateThu, 12 Dec 2019 09:53:26 +0000
treeherdermozilla-central@192e0e33eb59 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmgaudet
bugs1592307
milestone73.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 1592307: Part 9: SmallVector r=mgaudet SmallVector, like js::Vector, starts with elements allocated inline and expands when full. It is implemented as a wrapper around js::Vector. Depends on D56493 Differential Revision: https://phabricator.services.mozilla.com/D56494
js/src/new-regexp/util/vector.h
--- a/js/src/new-regexp/util/vector.h
+++ b/js/src/new-regexp/util/vector.h
@@ -158,11 +158,47 @@ class Vector {
 
 // The resulting vector does not contain a null-termination byte. If you want
 // the null byte, use ArrayVector("foo").
 inline Vector<const char> CStrVector(const char* data) {
   return Vector<const char>(data, strlen(data));
 }
 
 }  // namespace internal
+
+namespace base {
+
+// SmallVector uses inline storage first, and reallocates when full.
+// It is basically equivalent to js::Vector, and is implemented
+// as a thin wrapper.
+// V8's implementation: https://github.com/v8/v8/blob/master/src/base/small-vector.h
+template <typename T, size_t kSize>
+class SmallVector {
+public:
+  inline bool empty() const { return inner_.empty(); }
+  inline const T& back() const { return inner_.back(); }
+  inline void pop_back() { inner_.popBack(); };
+  template <typename... Args>
+  inline void emplace_back(Args&&... args) {
+    js::AutoEnterOOMUnsafeRegion oomUnsafe;
+    if (!inner_.emplaceBack(args...)) {
+      oomUnsafe.crash("Irregexp SmallVector emplace_back");
+    }
+  };
+  inline size_t size() const { return inner_.length(); }
+  inline const T& at(size_t index) const { return inner_[index]; }
+
+  void resize_no_init(size_t new_size) {
+    js::AutoEnterOOMUnsafeRegion oomUnsafe;
+    if (!inner_.resizeUninitialized(new_size)) {
+      oomUnsafe.crash("Irregexp SmallVector resize");
+    }
+  }
+private:
+  js::Vector<T, kSize, js::SystemAllocPolicy> inner_;
+};
+
+
+} // namespace base
+
 }  // namespace v8
 
 #endif  // V8_UTIL_VECTOR_H_