Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 10d3da8

Browse files
author
David Teller
committed
Bug 1581875 - Improving documentation of XXXHuffmanTable::lookup;r=arai
Differential Revision: https://phabricator.services.mozilla.com/D46952 --HG-- extra : moz-landing-system : lando
1 parent 6a88114 commit 10d3da8

2 files changed

Lines changed: 34 additions & 31 deletions

File tree

js/src/frontend/BinASTTokenReaderContext.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,6 @@ static_assert(
5959
// more bites than necessary, just to be on the safe side.
6060
const uint8_t MAX_PREFIX_BIT_LENGTH = 32;
6161

62-
// Maximal bit length acceptable in a `HuffmanTableSaturated`.
63-
//
64-
// As `HuffmanTableSaturated` require O(2 ^ max bit len) space, we
65-
// cannot afford to use them for all tables. Whenever the max bit
66-
// length in the table is <= MAX_BIT_LENGTH_IN_SATURATED_TABLE,
67-
// we use a `HuffmanTableSaturated`. Otherwise, we fall back to
68-
// a slower but less memory-hungry solution.
69-
const uint8_t MAX_BIT_LENGTH_IN_SATURATED_TABLE = 10;
70-
7162
// The length of the bit buffer, in bits.
7263
const uint8_t BIT_BUFFER_SIZE = 64;
7364

@@ -2053,7 +2044,7 @@ JS::Result<Ok> SingleLookupHuffmanTable<T>::initWithSingleValue(JSContext* cx,
20532044
template <typename T>
20542045
JS::Result<Ok> SingleLookupHuffmanTable<T>::initStart(
20552046
JSContext* cx, size_t numberOfSymbols, uint8_t largestBitLength) {
2056-
MOZ_ASSERT(largestBitLength <= MAX_BIT_LENGTH_IN_SATURATED_TABLE);
2047+
MOZ_ASSERT_IF(largestBitLength != 32, uint32_t(1) << largestBitLength <= mozilla::MaxValue<InternalIndex>::value);
20572048
MOZ_ASSERT(values.empty()); // Make sure that we're initializing.
20582049

20592050
this->largestBitLength = largestBitLength;

js/src/frontend/BinASTTokenReaderContext.h

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,16 @@ class NaiveHuffmanTable {
236236

237237
// Lookup a value in the table.
238238
//
239-
// Return an entry with a value of `nullptr` if the value is not in the table.
239+
// The return of this method contains:
240240
//
241-
// The lookup may advance `key` by `[0, key.bitLength]` bits. Typically, in a
242-
// table with a single instance, or if the value is not in the table, it
243-
// will advance by 0 bits. The caller is responsible for advancing its
244-
// bitstream by `result.key.bitLength` bits.
245-
HuffmanEntry<const T*> lookup(HuffmanLookup key) const;
241+
// - the resulting value (`nullptr` if the value is not in the table);
242+
// - the number of bits in the entry associated to this value.
243+
//
244+
// Note that entries inside a single table are typically associated to
245+
// distinct bit lengths. The caller is responsible for checking
246+
// the result of this method and advancing the bitstream by
247+
// `result.key.bitLength` bits.
248+
HuffmanEntry<const T*> lookup(HuffmanLookup lookup) const;
246249

247250
// The number of values in the table.
248251
size_t length() const { return values.length(); }
@@ -459,12 +462,15 @@ class SingleLookupHuffmanTable {
459462

460463
// Lookup a value in the table.
461464
//
462-
// Return an entry with a value of `nullptr` if the value is not in the table.
465+
// The return of this method contains:
463466
//
464-
// The lookup may advance `key` by `[0, key.bitLength]` bits. Typically, in a
465-
// table with a single instance, or if the value is not in the table, it
466-
// will advance by 0 bits. The caller is responsible for advancing its
467-
// bitstream by `result.key.bitLength` bits.
467+
// - the resulting value (`nullptr` if the value is not in the table);
468+
// - the number of bits in the entry associated to this value.
469+
//
470+
// Note that entries inside a single table are typically associated to
471+
// distinct bit lengths. The caller is responsible for checking
472+
// the result of this method and advancing the bitstream by
473+
// `result.key.bitLength` bits.
468474
HuffmanEntry<const T*> lookup(HuffmanLookup key) const;
469475

470476
// The number of values in the table.
@@ -654,12 +660,15 @@ class MultiLookupHuffmanTable {
654660

655661
// Lookup a value in the table.
656662
//
657-
// Return an entry with a value of `nullptr` if the value is not in the table.
663+
// The return of this method contains:
658664
//
659-
// The lookup may advance `key` by `[0, key.bitLength]` bits. Typically, in a
660-
// table with a single instance, or if the value is not in the table, it
661-
// will advance by 0 bits. The caller is responsible for advancing its
662-
// bitstream by `result.key.bitLength` bits.
665+
// - the resulting value (`nullptr` if the value is not in the table);
666+
// - the number of bits in the entry associated to this value.
667+
//
668+
// Note that entries inside a single table are typically associated to
669+
// distinct bit lengths. The caller is responsible for checking
670+
// the result of this method and advancing the bitstream by
671+
// `result.key.bitLength` bits.
663672
HuffmanEntry<const T*> lookup(HuffmanLookup key) const;
664673

665674
// The number of values in the table.
@@ -786,12 +795,15 @@ struct GenericHuffmanTable {
786795

787796
// Lookup a value in the table.
788797
//
789-
// Return an entry with a value of `nullptr` if the value is not in the table.
798+
// The return of this method contains:
790799
//
791-
// The lookup may advance `key` by `[0, key.bitLength]` bits. Typically, in a
792-
// table with a single instance, or if the value is not in the table, it
793-
// will advance by 0 bits. The caller is responsible for advancing its
794-
// bitstream by `result.key.bitLength` bits.
800+
// - the resulting value (`nullptr` if the value is not in the table);
801+
// - the number of bits in the entry associated to this value.
802+
//
803+
// Note that entries inside a single table are typically associated to
804+
// distinct bit lengths. The caller is responsible for checking
805+
// the result of this method and advancing the bitstream by
806+
// `result.key.bitLength` bits.
795807
HuffmanEntry<const T*> lookup(HuffmanLookup key) const;
796808

797809
private:

0 commit comments

Comments
 (0)