1
0
Fork 0
mirror of https://github.com/demostf/demo.js synced 2026-06-04 09:04:13 +02:00

fix guessing string table length

This commit is contained in:
Robin Appelman 2017-09-27 00:09:00 +02:00
commit 9c5e5648b5

View file

@ -83,11 +83,13 @@ export function parseStringTableEntries(
export function guessStringTableEntryLength(table: StringTable, entries: StringTableEntry[]): number { export function guessStringTableEntryLength(table: StringTable, entries: StringTableEntry[]): number {
// a rough guess of how many bytes are needed to encode the table entries // 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 entries.reduce((length: number, entry: StringTableEntry) => {
return length + return length +
entryBytes + entryBits +
1 + // new index bit
1 + // misc boolean 1 + // misc boolean
1 + // substring bit
entry.text.length + 1 + // +1 for null termination entry.text.length + 1 + // +1 for null termination
(entry.extraData ? Math.ceil(entry.extraData.length / 8) : 0); (entry.extraData ? Math.ceil(entry.extraData.length / 8) : 0);
}, 1); }, 1);