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:
David Teller 2019-09-13 10:32:21 +00:00
parent 1785543e7b
commit 4145187bc9
2 changed files with 19 additions and 6 deletions

View File

@ -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>>()

View File

@ -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.
//