Skip to content

Commit

Permalink
refactor: Improve readVector internals.
Browse files Browse the repository at this point in the history
  • Loading branch information
jheer committed Aug 31, 2024
1 parent 67d9163 commit 789dcbd
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,13 @@ export function readString(buf, index) {
*/
export function readVector(buf, offset, stride, extract) {
if (!offset) return [];
const length = readInt32(buf, offset + readInt32(buf, offset));
const base = offset + readInt32(buf, offset) + SIZEOF_INT;
return Array.from({ length }, (_, i) => extract(buf, base + i * stride))

// get base position by adding offset delta
const base = offset + readInt32(buf, offset);

// read vector size, extract entries
return Array.from(
{ length: readInt32(buf, base) },
(_, i) => extract(buf, base + SIZEOF_INT + i * stride)
);
}

0 comments on commit 789dcbd

Please sign in to comment.