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

Disable an incorrect optimization in int64ToString #366

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion packages/runtime/spec/pb-long.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {PbLong, PbULong} from "../src";
import {int64toString} from '../src/goog-varint';


describe('PbULong', function () {
Expand Down Expand Up @@ -72,6 +73,14 @@ describe('PbULong', function () {
expect(ulong.lo).toBe(0);
});

it('int64toString should serialize the same was as BigInt.toString()', function () {
let ulong = PbULong.from(1661324400000);
expect(ulong.hi).toBe(386);
expect(ulong.lo).toBe(-827943552);
expect(ulong.toString()).toBe('1661324400000')
expect(int64toString(ulong.lo, ulong.hi)).toBe('1661324400000')
});

});


Expand Down Expand Up @@ -302,4 +311,3 @@ describe('testing native bigint', function () {
});

});

6 changes: 0 additions & 6 deletions packages/runtime/src/goog-varint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,6 @@ export function int64fromString(dec: string): [boolean, number, number] {
* Copyright 2008 Google Inc.
*/
export function int64toString(bitsLow: number, bitsHigh: number): string {
// Skip the expensive conversion if the number is small enough to use the
// built-in conversions.
if (bitsHigh <= 0x1FFFFF) {
return '' + (TWO_PWR_32_DBL * bitsHigh + bitsLow);
}

// What this code is doing is essentially converting the input number from
// base-2 to base-1e7, which allows us to represent the 64-bit range with
// only 3 (very large) digits. Those digits are then trivial to convert to
Expand Down