mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 15:23:51 +00:00
Bug 1579862 - Documenting HuffmanTableImplementationSaturated::InternalIndex;r=arai
Differential Revision: https://phabricator.services.mozilla.com/D45825 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
1785543e7b
commit
4145187bc9
@ -6,8 +6,9 @@
|
||||
|
||||
#include "frontend/BinASTTokenReaderContext.h"
|
||||
|
||||
#include "mozilla/Result.h" // MOZ_TRY*
|
||||
#include "mozilla/ScopeExit.h" // mozilla::MakeScopeExit
|
||||
#include "mozilla/IntegerTypeTraits.h" // mozilla::MaxValue
|
||||
#include "mozilla/Result.h" // MOZ_TRY*
|
||||
#include "mozilla/ScopeExit.h" // mozilla::MakeScopeExit
|
||||
|
||||
#include <string.h> // memchr, memcmp, memmove
|
||||
|
||||
@ -1785,8 +1786,15 @@ JS::Result<Ok> HuffmanTableImplementationGeneric<T>::init(
|
||||
JSContext* cx, size_t numberOfSymbols, uint8_t maxBitLength) {
|
||||
MOZ_ASSERT(this->implementation.template is<
|
||||
HuffmanTableUnreachable>()); // Make sure that we're initializing.
|
||||
if (maxBitLength > MAX_BIT_LENGTH_IN_SATURATED_TABLE ||
|
||||
numberOfSymbols > 256) {
|
||||
if (
|
||||
// If the bit length is too large, don't put it in a saturated table
|
||||
// as this would need too much space.
|
||||
maxBitLength > MAX_BIT_LENGTH_IN_SATURATED_TABLE ||
|
||||
// If there are too many symbols, don't put it in a saturated table
|
||||
// as indices wouldn't fit into `InternalIndex` .
|
||||
numberOfSymbols >
|
||||
mozilla::MaxValue<typename HuffmanTableImplementationSaturated<
|
||||
T>::InternalIndex>::value) {
|
||||
this->implementation = {
|
||||
mozilla::VariantType<HuffmanTableImplementationMap<T>>{}, cx};
|
||||
MOZ_TRY(this->implementation.template as<HuffmanTableImplementationMap<T>>()
|
||||
|
@ -451,6 +451,12 @@ class HuffmanTableImplementationSaturated {
|
||||
Iterator begin() const { return Iterator(values.begin()); }
|
||||
Iterator end() const { return Iterator(values.end()); }
|
||||
|
||||
public:
|
||||
// An index into table `values`.
|
||||
// We use `uint8_t` instead of `size_t` to limit the space
|
||||
// used by the table.
|
||||
using InternalIndex = uint8_t;
|
||||
|
||||
private:
|
||||
// The entries in this Huffman Table, sorted in the order of insertion.
|
||||
//
|
||||
@ -460,12 +466,11 @@ class HuffmanTableImplementationSaturated {
|
||||
Vector<HuffmanEntry<T>> values;
|
||||
|
||||
// The entries in this Huffman table, prepared for lookup.
|
||||
// The `size_t` argument is an index into `values`.
|
||||
//
|
||||
// Invariant (once `init*` has been called):
|
||||
// - Length is `1 << maxBitLength`.
|
||||
// - for all i, `saturated[i] < values.length()`
|
||||
Vector<uint8_t> saturated;
|
||||
Vector<InternalIndex> saturated;
|
||||
|
||||
// The maximal bitlength of a value in this table.
|
||||
//
|
||||
|
Loading…
Reference in New Issue
Block a user