Open Bug 1306692 Opened 8 years ago Updated 2 years ago

Implement a pointer-based-iterator escape hatch for nsTArray

Categories

(Core :: XPCOM, defect, P3)

defect

Tracking

()

People

(Reporter: nika, Unassigned)

References

Details

In bug 1299489 we changed nsTArray's iterator to use the indexing mechanism instead of directly using pointers into the backing memory. In some situations this may be slower, despite it being faster. We may want to implement a form of pointer based escape hatch for the times when we know it's safe, and we want to get that extra performance.

It would probably look something like this (from bug 1299489 comment 20):

// strawman skeleton impl:
template<typename T>
class LocalIterate {
public:
  LocalIterate(nsTArray<T>& aArray) : mArray(aArray) {}
  T* begin() { return aArray.Elements(); }
  T* end() { return aArray.Elements() + aArray.Length(); }
  const T* begin() const { return aArray.Elements(); }
  const T* end() const { return aArray.Elements() + aArray.Length(); }
private:
  nsTArray<T>& mArray;
};
Priority: -- → P3
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.