зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1633741 - Add TrailingArray::numElements helper. r=jandem
This gives more readability to (end - start) / sizeof(T) computations to cleanup the IonScript data type. Differential Revision: https://phabricator.services.mozilla.com/D72944
This commit is contained in:
Родитель
76834dba34
Коммит
a87cd9908b
|
@ -283,8 +283,8 @@ struct alignas(8) IonScript final : public TrailingArray {
|
|||
return offsetToPointer<PreBarrieredValue>(constantTableOffset());
|
||||
}
|
||||
size_t numConstants() const {
|
||||
return (runtimeDataOffset() - constantTableOffset()) /
|
||||
sizeof(PreBarrieredValue);
|
||||
return numElements<PreBarrieredValue>(constantTableOffset(),
|
||||
runtimeDataOffset());
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -294,7 +294,7 @@ struct alignas(8) IonScript final : public TrailingArray {
|
|||
return offsetToPointer<uint8_t>(runtimeDataOffset());
|
||||
}
|
||||
size_t runtimeSize() const {
|
||||
return (osiIndexOffset() - runtimeDataOffset()) / sizeof(uint8_t);
|
||||
return numElements<uint8_t>(runtimeDataOffset(), osiIndexOffset());
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -305,7 +305,8 @@ struct alignas(8) IonScript final : public TrailingArray {
|
|||
return offsetToPointer<OsiIndex>(osiIndexOffset());
|
||||
}
|
||||
size_t numOsiIndices() const {
|
||||
return (safepointIndexOffset() - osiIndexOffset()) / SizeOf_OsiIndex;
|
||||
return numElements<SizeOf_OsiIndex>(osiIndexOffset(),
|
||||
safepointIndexOffset());
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -318,8 +319,8 @@ struct alignas(8) IonScript final : public TrailingArray {
|
|||
return offsetToPointer<SafepointIndex>(safepointIndexOffset());
|
||||
}
|
||||
size_t numSafepointIndices() const {
|
||||
return (bailoutTableOffset() - safepointIndexOffset()) /
|
||||
SizeOf_SafepointIndex;
|
||||
return numElements<SizeOf_SafepointIndex>(safepointIndexOffset(),
|
||||
bailoutTableOffset());
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -329,7 +330,8 @@ struct alignas(8) IonScript final : public TrailingArray {
|
|||
return offsetToPointer<SnapshotOffset>(bailoutTableOffset());
|
||||
}
|
||||
size_t numBailoutEntries() const {
|
||||
return (icIndexOffset() - bailoutTableOffset()) / SizeOf_SnapshotOffset;
|
||||
return numElements<SizeOf_SnapshotOffset>(bailoutTableOffset(),
|
||||
icIndexOffset());
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -337,7 +339,7 @@ struct alignas(8) IonScript final : public TrailingArray {
|
|||
//
|
||||
uint32_t* icIndex() { return offsetToPointer<uint32_t>(icIndexOffset()); }
|
||||
size_t numICs() const {
|
||||
return (safepointsOffset() - icIndexOffset()) / sizeof(uint32_t);
|
||||
return numElements<uint32_t>(icIndexOffset(), safepointsOffset());
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -347,7 +349,7 @@ struct alignas(8) IonScript final : public TrailingArray {
|
|||
return offsetToPointer<uint8_t>(safepointsOffset());
|
||||
}
|
||||
size_t safepointsSize() const {
|
||||
return (snapshotsOffset() - safepointsOffset()) / sizeof(uint8_t);
|
||||
return numElements<uint8_t>(safepointsOffset(), snapshotsOffset());
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -357,10 +359,10 @@ struct alignas(8) IonScript final : public TrailingArray {
|
|||
return offsetToPointer<uint8_t>(snapshotsOffset());
|
||||
}
|
||||
size_t snapshotsListSize() const {
|
||||
return (rvaTableOffset() - snapshotsOffset()) / sizeof(uint8_t);
|
||||
return numElements<uint8_t>(snapshotsOffset(), rvaTableOffset());
|
||||
}
|
||||
size_t snapshotsRVATableSize() const {
|
||||
return (recoversOffset() - rvaTableOffset()) / sizeof(uint8_t);
|
||||
return numElements<uint8_t>(rvaTableOffset(), recoversOffset());
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -370,7 +372,7 @@ struct alignas(8) IonScript final : public TrailingArray {
|
|||
return offsetToPointer<uint8_t>(recoversOffset());
|
||||
}
|
||||
size_t recoversSize() const {
|
||||
return (endOffset() - recoversOffset()) / sizeof(uint8_t);
|
||||
return numElements<uint8_t>(recoversOffset(), endOffset());
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
|
@ -304,11 +304,11 @@ class alignas(uintptr_t) JitScript final : public TrailingArray {
|
|||
}
|
||||
|
||||
uint32_t numICEntries() const {
|
||||
return (typeSetOffset() - icEntriesOffset()) / sizeof(ICEntry);
|
||||
return numElements<ICEntry>(icEntriesOffset(), typeSetOffset());
|
||||
}
|
||||
uint32_t numTypeSets() const {
|
||||
MOZ_ASSERT(IsTypeInferenceEnabled());
|
||||
return (bytecodeTypeMapOffset() - typeSetOffset()) / sizeof(StackTypeSet);
|
||||
return numElements<StackTypeSet>(typeSetOffset(), bytecodeTypeMapOffset());
|
||||
}
|
||||
|
||||
uint32_t* bytecodeTypeMapHint() { return &bytecodeTypeMapHint_; }
|
||||
|
|
|
@ -61,6 +61,19 @@ class TrailingArray {
|
|||
}
|
||||
}
|
||||
|
||||
// Compute the length of an array from its start and end offset.
|
||||
template <typename T>
|
||||
size_t numElements(Offset start, Offset end) const {
|
||||
constexpr size_t ElemSize = sizeof(T);
|
||||
return numElements<ElemSize>(start, end);
|
||||
}
|
||||
template <size_t ElemSize>
|
||||
size_t numElements(Offset start, Offset end) const {
|
||||
MOZ_ASSERT(start <= end);
|
||||
MOZ_ASSERT((end - start) % ElemSize == 0);
|
||||
return (end - start) / ElemSize;
|
||||
}
|
||||
|
||||
// Constructor is protected so a derived type is required.
|
||||
TrailingArray() = default;
|
||||
|
||||
|
|
|
@ -368,7 +368,9 @@ class alignas(uint32_t) ImmutableScriptData final : public TrailingArray {
|
|||
jsbytecode* code() { return offsetToPointer<jsbytecode>(codeOffset()); }
|
||||
mozilla::Span<jsbytecode> codeSpan() { return {code(), codeLength()}; }
|
||||
|
||||
uint32_t noteLength() const { return optionalOffsetsOffset() - noteOffset(); }
|
||||
uint32_t noteLength() const {
|
||||
return numElements<SrcNote>(noteOffset(), optionalOffsetsOffset());
|
||||
}
|
||||
SrcNote* notes() { return offsetToPointer<SrcNote>(noteOffset()); }
|
||||
mozilla::Span<SrcNote> notesSpan() { return {notes(), noteLength()}; }
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче