Skip to content

Commit

Permalink
fix(typedarray): remove fast io path until we properly check for alig…
Browse files Browse the repository at this point in the history
…nment
  • Loading branch information
fallenoak committed Dec 21, 2023
1 parent 087a621 commit cf726d7
Showing 1 changed file with 3 additions and 25 deletions.
28 changes: 3 additions & 25 deletions src/lib/type/TypedArrayIo.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
Endianness,
IoMode,
RUNTIME_ENDIANNESS,
validateType,
} from '../util.js';
import { Endianness, IoMode, validateType } from '../util.js';
import { openStream } from '../stream/util.js';
import { IoSource, IoType } from '../types.js';
import * as io from '../io/numeric.js';
Expand Down Expand Up @@ -108,13 +103,6 @@ class TypedArrayIo implements IoType {
this.#type = type;
this.#options = options;
this.#arrayConstructor = CONSTRUCTOR_MAP.get(this.#type);

// If type endianness matches runtime endianness, we'll back the typed array with raw bytes
this.#fastIo =
(RUNTIME_ENDIANNESS === Endianness.Little &&
EXPLICIT_LITTLE_ENDIAN.has(this.#type)) ||
(RUNTIME_ENDIANNESS === Endianness.Big &&
EXPLICIT_BIG_ENDIAN.has(this.#type));
}

getSize(value: any[]) {
Expand All @@ -140,12 +128,6 @@ class TypedArrayIo implements IoType {

// Fixed size reads

if (this.#fastIo) {
const size = this.#type.getSize(undefined) * this.#options.size;
const bytes = stream.readBytes(size);
return new this.#arrayConstructor(bytes.buffer);
}

const value = new this.#arrayConstructor(this.#options.size);

for (let i = 0; i < this.#options.size; i++) {
Expand All @@ -159,12 +141,8 @@ class TypedArrayIo implements IoType {
const stream = openStream(source, IoMode.Write, this.#options.endianness);
const expectedEndOffset = stream.offset + this.getSize(undefined);

if (this.#fastIo) {
stream.writeBytes(new Uint8Array(value.buffer));
} else {
for (let i = 0; i < value.length; i++) {
this.#type.write(stream, value[i]);
}
for (let i = 0; i < value.length; i++) {
this.#type.write(stream, value[i]);
}

if (stream.offset !== expectedEndOffset) {
Expand Down

0 comments on commit cf726d7

Please sign in to comment.