From 2d68262f5f8e33494b41a05cb43f9e6a3abd7ac0 Mon Sep 17 00:00:00 2001 From: Khushboo Desai Date: Fri, 20 Nov 2020 12:49:44 -0800 Subject: [PATCH 1/3] modified binary reader and parser for performance improvements --- src/IonBinaryReader.ts | 5 ----- src/IonParserBinaryRaw.ts | 9 +++++---- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/IonBinaryReader.ts b/src/IonBinaryReader.ts index 07380ca3..02a96553 100644 --- a/src/IonBinaryReader.ts +++ b/src/IonBinaryReader.ts @@ -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"); diff --git a/src/IonParserBinaryRaw.ts b/src/IonParserBinaryRaw.ts index d939e1c1..188e3f9b 100644 --- a/src/IonParserBinaryRaw.ts +++ b/src/IonParserBinaryRaw.ts @@ -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; } From 5893dd2e48b62c82561cdefa8d989aed8db7b202 Mon Sep 17 00:00:00 2001 From: Khushboo Desai Date: Fri, 20 Nov 2020 12:54:40 -0800 Subject: [PATCH 2/3] print symbolId in the error for maxId --- src/IonLocalSymbolTable.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/IonLocalSymbolTable.ts b/src/IonLocalSymbolTable.ts index b87ce972..fd7a6886 100644 --- a/src/IonLocalSymbolTable.ts +++ b/src/IonLocalSymbolTable.ts @@ -74,7 +74,7 @@ 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 From 60c3869323b8d8e73bc922ad2943044cc78a976b Mon Sep 17 00:00:00 2001 From: Khushboo Desai Date: Fri, 20 Nov 2020 13:09:56 -0800 Subject: [PATCH 3/3] prettier changes --- src/IonLocalSymbolTable.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/IonLocalSymbolTable.ts b/src/IonLocalSymbolTable.ts index fd7a6886..06c3b80f 100644 --- a/src/IonLocalSymbolTable.ts +++ b/src/IonLocalSymbolTable.ts @@ -74,7 +74,9 @@ export class LocalSymbolTable { getSymbolText(symbolId: number): string | null { if (symbolId > this.maxId) { - throw new Error("Symbol $" + symbolId.toString() + " greater than maxID."); + throw new Error( + "Symbol $" + symbolId.toString() + " greater than maxID." + ); } const importedSymbol: string | undefined = this.import.getSymbolText( symbolId