dredless 1.4.0 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dredless",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
4
4
  "description": "A fully-featured and from-scratch headless drednot.io client implementation written in pure js.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/certainhuman/dredless#readme",
@@ -16,14 +16,18 @@ export class ModelReader {
16
16
  }
17
17
 
18
18
  readUnsigned() {
19
- let result = 0;
20
- let shift = 0;
19
+ const first = this.readByte();
20
+ if (first < 0x80) return first;
21
+ let result = first & 0x7f;
22
+ let multiplier = 128;
23
+ let shift = 7;
21
24
  while (true) {
22
25
  const byte = this.readByte();
23
- result += (byte & 0x7f) * (2 ** shift);
26
+ result += (byte & 0x7f) * multiplier;
24
27
  if ((byte & 0x80) === 0) return result;
25
28
  shift += 7;
26
29
  if (shift > 70) throw new Error("model_data varint too large");
30
+ multiplier *= 128;
27
31
  }
28
32
  }
29
33
 
@@ -1155,6 +1155,8 @@ export class ModelState {
1155
1155
 
1156
1156
  #readSectionRecords(reader, tag, tableId, spec) {
1157
1157
  const section = {tag, table: tableId, name: spec?.name || null, records: []};
1158
+ // Resolve the table once per section rather than twice per record.
1159
+ let records = this.tables.get(tableId);
1158
1160
  let entity = 0;
1159
1161
  while (reader.remaining > 0) {
1160
1162
  const recordOffset = reader.offset;
@@ -1172,7 +1174,9 @@ export class ModelState {
1172
1174
  } catch (error) {
1173
1175
  throw new Error(`model table ${tableId} tag ${tag} entity ${entity} mask offset ${reader.offset}: ${error.message}`);
1174
1176
  }
1175
- const record = this.#getRecord(tableId, entity);
1177
+ if (!records) this.tables.set(tableId, records = new Map());
1178
+ let record = records.get(entity);
1179
+ if (!record) records.set(entity, record = {...spec?.defaults});
1176
1180
  record.lastMask = mask;
1177
1181
 
1178
1182
  try {
@@ -1188,13 +1192,6 @@ export class ModelState {
1188
1192
  return section;
1189
1193
  }
1190
1194
 
1191
- #getRecord(tableId, entity) {
1192
- if (!this.tables.has(tableId)) this.tables.set(tableId, new Map());
1193
- const records = this.tables.get(tableId);
1194
- if (!records.has(entity)) records.set(entity, {...MODEL_TABLE_SPECS.get(tableId)?.defaults});
1195
- return records.get(entity);
1196
- }
1197
-
1198
1195
  #applyRecordSpec(reader, record, mask, spec) {
1199
1196
  if (typeof spec.read === "function") {
1200
1197
  spec.read(reader, record, mask);