Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binary Reader performance improvement #647

Merged
merged 3 commits into from
Nov 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions src/IonBinaryReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,6 @@ export class BinaryReader implements Reader {
return null;
}
if (symbolId > 0) {
if (symbolId > this._symtab.maxId) {
throw new Error(
"Symbol $" + symbolId.toString() + " greater than maxID."
);
}
s = this._symtab.getSymbolText(symbolId);
if (s === undefined) {
throw new Error("symbol is unresolvable");
Expand Down
4 changes: 3 additions & 1 deletion src/IonLocalSymbolTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ export class LocalSymbolTable {

getSymbolText(symbolId: number): string | null {
if (symbolId > this.maxId) {
throw new Error("SymbolID greater than maxID.");
throw new Error(
"Symbol $" + symbolId.toString() + " greater than maxID."
);
}
const importedSymbol: string | undefined = this.import.getSymbolText(
symbolId
Expand Down
9 changes: 5 additions & 4 deletions src/IonParserBinaryRaw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,13 @@ export class ParserBinaryRaw {
while (bytesRead < numberOfBytes) {
byte = input.next();
bytesRead++;
// TODO: Bitshifting is faster than multiplication because it converts numbers to integer values,
// but it loses precision on values larger than 31 bits. Consider optimizing this code path
// for smaller values of `numberOfBytes`.

// Avoid using bitshifting to preserve Number's precision beyond 31 bits.
value *= 256;
if (numberOfBytes < 4) {
value <<= 8;
} else {
value *= 256;
}
value = value + byte;
}

Expand Down