mirror of
https://github.com/morluto/rea.git
synced 2026-12-06 15:33:56 +08:00
refactor(pickle): reuse decoded decimal operand text (#17308)
This commit is contained in:
@@ -435,8 +435,8 @@ export class PickleWalker {
|
||||
* A protocol 0 decimal argument. Digits past the exact binary-long bound are
|
||||
* validated but not converted, so one opcode cannot force an unbounded BigInt.
|
||||
*/
|
||||
#decimal(line: Buffer, what: string): bigint | null {
|
||||
const text = line.toString("latin1").trim();
|
||||
#decimal(line: string, what: string): bigint | null {
|
||||
const text = line.trim();
|
||||
if (!/^[+-]?[0-9]+$/u.test(text))
|
||||
throw this.malformed(`Pickle ${what} argument is not a decimal integer`);
|
||||
const digits = text.length - (/^[+-]/u.test(text) ? 1 : 0);
|
||||
@@ -445,7 +445,7 @@ export class PickleWalker {
|
||||
|
||||
/** A protocol 0 GET or PUT memo key, which must be exact. */
|
||||
#decimalKey(what: string): bigint {
|
||||
const key = this.#decimal(this.#line(), what);
|
||||
const key = this.#decimal(this.#line().toString("latin1"), what);
|
||||
if (key === null)
|
||||
throw this.malformed(`Pickle ${what} memo key exceeds exact precision`);
|
||||
return key;
|
||||
@@ -668,19 +668,14 @@ export class PickleWalker {
|
||||
this.#bytes(8);
|
||||
return push(FLOAT);
|
||||
case 0x49: {
|
||||
const line = this.#line();
|
||||
const text = line.toString("latin1");
|
||||
const text = this.#line().toString("latin1");
|
||||
if (text === "00") return push({ kind: "bool", value: false });
|
||||
if (text === "01") return push({ kind: "bool", value: true });
|
||||
return push({ kind: "int", value: this.#decimal(line, "INT") });
|
||||
return push({ kind: "int", value: this.#decimal(text, "INT") });
|
||||
}
|
||||
case 0x4c: {
|
||||
const line = this.#line();
|
||||
const text = line.toString("latin1").replace(/L$/u, "");
|
||||
return push({
|
||||
kind: "int",
|
||||
value: this.#decimal(Buffer.from(text, "latin1"), "LONG"),
|
||||
});
|
||||
const text = this.#line().toString("latin1").replace(/L$/u, "");
|
||||
return push({ kind: "int", value: this.#decimal(text, "LONG") });
|
||||
}
|
||||
case 0x4a:
|
||||
return push({
|
||||
|
||||
Reference in New Issue
Block a user