mirror of
https://github.com/demostf/demo.js
synced 2026-06-04 00:54:14 +02:00
fix guessing string table length
This commit is contained in:
parent
7505abc6d0
commit
9c5e5648b5
1 changed files with 4 additions and 2 deletions
|
|
@ -83,11 +83,13 @@ export function parseStringTableEntries(
|
|||
|
||||
export function guessStringTableEntryLength(table: StringTable, entries: StringTableEntry[]): number {
|
||||
// a rough guess of how many bytes are needed to encode the table entries
|
||||
const entryBytes = Math.ceil(logBase2(table.maxEntries) / 8);
|
||||
const entryBits = Math.ceil(logBase2(table.maxEntries) / 8);
|
||||
return entries.reduce((length: number, entry: StringTableEntry) => {
|
||||
return length +
|
||||
entryBytes +
|
||||
entryBits +
|
||||
1 + // new index bit
|
||||
1 + // misc boolean
|
||||
1 + // substring bit
|
||||
entry.text.length + 1 + // +1 for null termination
|
||||
(entry.extraData ? Math.ceil(entry.extraData.length / 8) : 0);
|
||||
}, 1);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue