зеркало из 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());
|
return offsetToPointer<PreBarrieredValue>(constantTableOffset());
|
||||||
}
|
}
|
||||||
size_t numConstants() const {
|
size_t numConstants() const {
|
||||||
return (runtimeDataOffset() - constantTableOffset()) /
|
return numElements<PreBarrieredValue>(constantTableOffset(),
|
||||||
sizeof(PreBarrieredValue);
|
runtimeDataOffset());
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -294,7 +294,7 @@ struct alignas(8) IonScript final : public TrailingArray {
|
||||||
return offsetToPointer<uint8_t>(runtimeDataOffset());
|
return offsetToPointer<uint8_t>(runtimeDataOffset());
|
||||||
}
|
}
|
||||||
size_t runtimeSize() const {
|
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());
|
return offsetToPointer<OsiIndex>(osiIndexOffset());
|
||||||
}
|
}
|
||||||
size_t numOsiIndices() const {
|
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());
|
return offsetToPointer<SafepointIndex>(safepointIndexOffset());
|
||||||
}
|
}
|
||||||
size_t numSafepointIndices() const {
|
size_t numSafepointIndices() const {
|
||||||
return (bailoutTableOffset() - safepointIndexOffset()) /
|
return numElements<SizeOf_SafepointIndex>(safepointIndexOffset(),
|
||||||
SizeOf_SafepointIndex;
|
bailoutTableOffset());
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -329,7 +330,8 @@ struct alignas(8) IonScript final : public TrailingArray {
|
||||||
return offsetToPointer<SnapshotOffset>(bailoutTableOffset());
|
return offsetToPointer<SnapshotOffset>(bailoutTableOffset());
|
||||||
}
|
}
|
||||||
size_t numBailoutEntries() const {
|
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()); }
|
uint32_t* icIndex() { return offsetToPointer<uint32_t>(icIndexOffset()); }
|
||||||
size_t numICs() const {
|
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());
|
return offsetToPointer<uint8_t>(safepointsOffset());
|
||||||
}
|
}
|
||||||
size_t safepointsSize() const {
|
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());
|
return offsetToPointer<uint8_t>(snapshotsOffset());
|
||||||
}
|
}
|
||||||
size_t snapshotsListSize() const {
|
size_t snapshotsListSize() const {
|
||||||
return (rvaTableOffset() - snapshotsOffset()) / sizeof(uint8_t);
|
return numElements<uint8_t>(snapshotsOffset(), rvaTableOffset());
|
||||||
}
|
}
|
||||||
size_t snapshotsRVATableSize() const {
|
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());
|
return offsetToPointer<uint8_t>(recoversOffset());
|
||||||
}
|
}
|
||||||
size_t recoversSize() const {
|
size_t recoversSize() const {
|
||||||
return (endOffset() - recoversOffset()) / sizeof(uint8_t);
|
return numElements<uint8_t>(recoversOffset(), endOffset());
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -304,11 +304,11 @@ class alignas(uintptr_t) JitScript final : public TrailingArray {
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t numICEntries() const {
|
uint32_t numICEntries() const {
|
||||||
return (typeSetOffset() - icEntriesOffset()) / sizeof(ICEntry);
|
return numElements<ICEntry>(icEntriesOffset(), typeSetOffset());
|
||||||
}
|
}
|
||||||
uint32_t numTypeSets() const {
|
uint32_t numTypeSets() const {
|
||||||
MOZ_ASSERT(IsTypeInferenceEnabled());
|
MOZ_ASSERT(IsTypeInferenceEnabled());
|
||||||
return (bytecodeTypeMapOffset() - typeSetOffset()) / sizeof(StackTypeSet);
|
return numElements<StackTypeSet>(typeSetOffset(), bytecodeTypeMapOffset());
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t* bytecodeTypeMapHint() { return &bytecodeTypeMapHint_; }
|
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.
|
// Constructor is protected so a derived type is required.
|
||||||
TrailingArray() = default;
|
TrailingArray() = default;
|
||||||
|
|
||||||
|
|
|
@ -368,7 +368,9 @@ class alignas(uint32_t) ImmutableScriptData final : public TrailingArray {
|
||||||
jsbytecode* code() { return offsetToPointer<jsbytecode>(codeOffset()); }
|
jsbytecode* code() { return offsetToPointer<jsbytecode>(codeOffset()); }
|
||||||
mozilla::Span<jsbytecode> codeSpan() { return {code(), codeLength()}; }
|
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()); }
|
SrcNote* notes() { return offsetToPointer<SrcNote>(noteOffset()); }
|
||||||
mozilla::Span<SrcNote> notesSpan() { return {notes(), noteLength()}; }
|
mozilla::Span<SrcNote> notesSpan() { return {notes(), noteLength()}; }
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче