зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1231224 part 12 - Use InfallibleVector in irregexp code to avoid MOZ_WARN_UNUSED_RESULT warnings. r=luke
--HG-- extra : rebase_source : 5b7eafd1d8105c4bba18efad6dcf0c5805caff95
This commit is contained in:
Родитель
e3c4b94f10
Коммит
ab5c363f7d
|
@ -82,7 +82,7 @@ class RegExpTree
|
|||
#undef MAKE_ASTYPE
|
||||
};
|
||||
|
||||
typedef Vector<RegExpTree*, 1, LifoAllocPolicy<Infallible> > RegExpTreeVector;
|
||||
typedef InfallibleVector<RegExpTree*, 1> RegExpTreeVector;
|
||||
|
||||
class RegExpDisjunction : public RegExpTree
|
||||
{
|
||||
|
@ -235,7 +235,7 @@ class RegExpCharacterClass : public RegExpTree
|
|||
bool is_negated_;
|
||||
};
|
||||
|
||||
typedef Vector<char16_t, 10, LifoAllocPolicy<Infallible> > CharacterVector;
|
||||
typedef InfallibleVector<char16_t, 10> CharacterVector;
|
||||
|
||||
class RegExpAtom : public RegExpTree
|
||||
{
|
||||
|
@ -403,7 +403,7 @@ class RegExpLookahead : public RegExpTree
|
|||
int capture_from_;
|
||||
};
|
||||
|
||||
typedef Vector<RegExpCapture*, 1, LifoAllocPolicy<Infallible> > RegExpCaptureVector;
|
||||
typedef InfallibleVector<RegExpCapture*, 1> RegExpCaptureVector;
|
||||
|
||||
class RegExpBackReference : public RegExpTree
|
||||
{
|
||||
|
|
|
@ -1116,9 +1116,7 @@ ChoiceNode::FilterASCII(int depth, bool ignore_case, bool unicode)
|
|||
alternatives()[i].node()->FilterASCII(depth - 1, ignore_case, unicode);
|
||||
if (replacement != nullptr) {
|
||||
alternatives()[i].set_node(replacement);
|
||||
AutoEnterOOMUnsafeRegion oomUnsafe;
|
||||
if (!new_alternatives.append(alternatives()[i]))
|
||||
oomUnsafe.crash("ChoiceNode::FilterASCII");
|
||||
new_alternatives.append(alternatives()[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3249,7 +3247,7 @@ EmitDoubleBoundaryTest(RegExpMacroAssembler* masm,
|
|||
}
|
||||
}
|
||||
|
||||
typedef Vector<int, 4, LifoAllocPolicy<Infallible> > RangeBoundaryVector;
|
||||
typedef InfallibleVector<int, 4> RangeBoundaryVector;
|
||||
|
||||
// even_label is for ranges[i] to ranges[i + 1] where i - start_index is even.
|
||||
// odd_label is for ranges[i] to ranges[i + 1] where i - start_index is odd.
|
||||
|
@ -4234,15 +4232,15 @@ class AlternativeGenerationList
|
|||
AlternativeGenerationList(LifoAlloc* alloc, size_t count)
|
||||
: alt_gens_(*alloc)
|
||||
{
|
||||
AutoEnterOOMUnsafeRegion oomUnsafe;
|
||||
alt_gens_.reserve(count);
|
||||
for (size_t i = 0; i < count && i < kAFew; i++)
|
||||
alt_gens_.infallibleAppend(a_few_alt_gens_ + i);
|
||||
alt_gens_.append(a_few_alt_gens_ + i);
|
||||
for (size_t i = kAFew; i < count; i++) {
|
||||
AutoEnterOOMUnsafeRegion oomUnsafe;
|
||||
AlternativeGeneration* gen = js_new<AlternativeGeneration>();
|
||||
if (!gen)
|
||||
oomUnsafe.crash("AlternativeGenerationList js_new");
|
||||
alt_gens_.infallibleAppend(gen);
|
||||
alt_gens_.append(gen);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4259,7 +4257,7 @@ class AlternativeGenerationList
|
|||
|
||||
private:
|
||||
static const size_t kAFew = 10;
|
||||
Vector<AlternativeGeneration*, 1, LifoAllocPolicy<Infallible> > alt_gens_;
|
||||
InfallibleVector<AlternativeGeneration*, 1> alt_gens_;
|
||||
AlternativeGeneration a_few_alt_gens_[kAFew];
|
||||
};
|
||||
|
||||
|
|
|
@ -128,8 +128,40 @@ InterpretCode(JSContext* cx, const uint8_t* byteCode, const CharT* chars, size_t
|
|||
FOR_EACH_REG_EXP_TREE_TYPE(FORWARD_DECLARE)
|
||||
#undef FORWARD_DECLARE
|
||||
|
||||
// InfallibleVector is like Vector, but all its methods are infallible (they
|
||||
// crash on OOM). We use this class instead of Vector to avoid a ton of
|
||||
// MOZ_WARN_UNUSED_RESULT warnings in irregexp code (imported from V8).
|
||||
template<typename T, size_t N>
|
||||
class InfallibleVector
|
||||
{
|
||||
Vector<T, N, LifoAllocPolicy<Infallible>> vector_;
|
||||
|
||||
InfallibleVector(const InfallibleVector&) = delete;
|
||||
void operator=(const InfallibleVector&) = delete;
|
||||
|
||||
public:
|
||||
explicit InfallibleVector(const LifoAllocPolicy<Infallible>& alloc) : vector_(alloc) {}
|
||||
|
||||
void append(const T& t) { MOZ_ALWAYS_TRUE(vector_.append(t)); }
|
||||
void append(const T* begin, size_t length) { MOZ_ALWAYS_TRUE(vector_.append(begin, length)); }
|
||||
|
||||
void clear() { vector_.clear(); }
|
||||
void popBack() { vector_.popBack(); }
|
||||
void reserve(size_t n) { MOZ_ALWAYS_TRUE(vector_.reserve(n)); }
|
||||
|
||||
size_t length() const { return vector_.length(); }
|
||||
T popCopy() { return vector_.popCopy(); }
|
||||
|
||||
T* begin() { return vector_.begin(); }
|
||||
|
||||
T& operator[](size_t index) { return vector_[index]; }
|
||||
const T& operator[](size_t index) const { return vector_[index]; }
|
||||
|
||||
InfallibleVector& operator=(InfallibleVector&& rhs) { vector_ = Move(rhs.vector_); return *this; }
|
||||
};
|
||||
|
||||
class CharacterRange;
|
||||
typedef Vector<CharacterRange, 1, LifoAllocPolicy<Infallible> > CharacterRangeVector;
|
||||
typedef InfallibleVector<CharacterRange, 1> CharacterRangeVector;
|
||||
|
||||
// Represents code units in the range from from_ to to_, both ends are
|
||||
// inclusive.
|
||||
|
@ -211,8 +243,8 @@ class OutSet
|
|||
static const unsigned kFirstLimit = 32;
|
||||
|
||||
private:
|
||||
typedef Vector<OutSet*, 1, LifoAllocPolicy<Infallible> > OutSetVector;
|
||||
typedef Vector<unsigned, 1, LifoAllocPolicy<Infallible> > RemainingVector;
|
||||
typedef InfallibleVector<OutSet*, 1> OutSetVector;
|
||||
typedef InfallibleVector<unsigned, 1> RemainingVector;
|
||||
|
||||
// Destructively set a value in this set. In most cases you want
|
||||
// to use Extend instead to ensure that only one instance exists
|
||||
|
@ -317,7 +349,7 @@ class TextElement
|
|||
RegExpTree* tree_;
|
||||
};
|
||||
|
||||
typedef Vector<TextElement, 1, LifoAllocPolicy<Infallible> > TextElementVector;
|
||||
typedef InfallibleVector<TextElement, 1> TextElementVector;
|
||||
|
||||
class NodeVisitor;
|
||||
class RegExpCompiler;
|
||||
|
@ -956,7 +988,7 @@ class Guard
|
|||
int value_;
|
||||
};
|
||||
|
||||
typedef Vector<Guard*, 1, LifoAllocPolicy<Infallible> > GuardVector;
|
||||
typedef InfallibleVector<Guard*, 1> GuardVector;
|
||||
|
||||
class GuardedAlternative
|
||||
{
|
||||
|
@ -975,7 +1007,7 @@ class GuardedAlternative
|
|||
GuardVector* guards_;
|
||||
};
|
||||
|
||||
typedef Vector<GuardedAlternative, 0, LifoAllocPolicy<Infallible> > GuardedAlternativeVector;
|
||||
typedef InfallibleVector<GuardedAlternative, 0> GuardedAlternativeVector;
|
||||
|
||||
class AlternativeGeneration;
|
||||
|
||||
|
@ -1189,7 +1221,7 @@ class BoyerMoorePositionInfo
|
|||
bool is_word() { return w_ == kLatticeIn; }
|
||||
|
||||
private:
|
||||
Vector<bool, 0, LifoAllocPolicy<Infallible> > map_;
|
||||
InfallibleVector<bool, 0> map_;
|
||||
int map_count_; // Number of set bits in the map.
|
||||
ContainedInLattice w_; // The \w character class.
|
||||
ContainedInLattice s_; // The \s character class.
|
||||
|
@ -1197,7 +1229,7 @@ class BoyerMoorePositionInfo
|
|||
ContainedInLattice surrogate_; // Surrogate UTF-16 code units.
|
||||
};
|
||||
|
||||
typedef Vector<BoyerMoorePositionInfo*, 1, LifoAllocPolicy<Infallible> > BoyerMoorePositionInfoVector;
|
||||
typedef InfallibleVector<BoyerMoorePositionInfo*, 1> BoyerMoorePositionInfoVector;
|
||||
|
||||
class BoyerMooreLookahead
|
||||
{
|
||||
|
|
|
@ -616,7 +616,7 @@ class WideCharRange
|
|||
widechar to_;
|
||||
};
|
||||
|
||||
typedef Vector<WideCharRange, 1, LifoAllocPolicy<Infallible> > WideCharRangeVector;
|
||||
typedef InfallibleVector<WideCharRange, 1> WideCharRangeVector;
|
||||
|
||||
static inline CharacterRange
|
||||
LeadSurrogateRange()
|
||||
|
@ -740,10 +740,10 @@ AddUnicodeRange(LifoAlloc* alloc,
|
|||
// encompassing the full range of possible values.
|
||||
template <typename RangeType>
|
||||
static inline void
|
||||
NegateUnicodeRanges(LifoAlloc* alloc, Vector<RangeType, 1, LifoAllocPolicy<Infallible> >** ranges,
|
||||
NegateUnicodeRanges(LifoAlloc* alloc, InfallibleVector<RangeType, 1>** ranges,
|
||||
RangeType full_range)
|
||||
{
|
||||
typedef Vector<RangeType, 1, LifoAllocPolicy<Infallible> > RangeVector;
|
||||
typedef InfallibleVector<RangeType, 1> RangeVector;
|
||||
RangeVector* tmp_ranges = alloc->newInfallible<RangeVector>(*alloc);
|
||||
tmp_ranges->append(full_range);
|
||||
RangeVector* result_ranges = alloc->newInfallible<RangeVector>(*alloc);
|
||||
|
|
|
@ -60,7 +60,7 @@ template <typename T, int initial_size>
|
|||
class BufferedVector
|
||||
{
|
||||
public:
|
||||
typedef Vector<T*, 1, LifoAllocPolicy<Infallible> > VectorType;
|
||||
typedef InfallibleVector<T*, 1> VectorType;
|
||||
|
||||
BufferedVector() : list_(nullptr), last_(nullptr) {}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче