Skip to content

Commit 7c58f97

Browse files
committed
reduce temp vars
1 parent c8c2f6e commit 7c58f97

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

src/Encoder.ts

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,10 @@ export class Encoder {
148148
const ext = this.extensionCodec.tryToEncode(object);
149149
if (ext != null) {
150150
this.encodeExtension(ext);
151-
} else if (ArrayBuffer.isView(object)) {
152-
this.encodeBinary(object);
153151
} else if (Array.isArray(object)) {
154152
this.encodeArray(object, depth);
153+
} else if (ArrayBuffer.isView(object)) {
154+
this.encodeBinary(object);
155155
} else if (typeof object === "object") {
156156
this.encodeMap(object as Record<string, unknown>, depth);
157157
} else {
@@ -263,7 +263,8 @@ export class Encoder {
263263
writeU8(value: number) {
264264
this.ensureBufferSizeToWrite(1);
265265

266-
this.view.setUint8(this.pos++, value);
266+
this.view.setUint8(this.pos, value);
267+
this.pos++;
267268
}
268269

269270
writeU8v(...values: ReadonlyArray<number>) {
@@ -280,62 +281,56 @@ export class Encoder {
280281
writeI8(value: number) {
281282
this.ensureBufferSizeToWrite(1);
282283

283-
this.view.setInt8(this.pos++, value);
284+
this.view.setInt8(this.pos, value);
285+
this.pos++;
284286
}
285287

286288
writeU16(value: number) {
287289
this.ensureBufferSizeToWrite(2);
288290

289-
const pos = this.pos;
291+
this.view.setUint16(this.pos, value);
290292
this.pos += 2;
291-
this.view.setUint16(pos, value);
292293
}
293294

294295
writeI16(value: number) {
295296
this.ensureBufferSizeToWrite(2);
296297

297-
const pos = this.pos;
298+
this.view.setInt16(this.pos, value);
298299
this.pos += 2;
299-
this.view.setInt16(pos, value);
300300
}
301301

302302
writeU32(value: number) {
303303
this.ensureBufferSizeToWrite(4);
304304

305-
const pos = this.pos;
305+
this.view.setUint32(this.pos, value);
306306
this.pos += 4;
307-
this.view.setUint32(pos, value);
308307
}
309308

310309
writeI32(value: number) {
311310
this.ensureBufferSizeToWrite(4);
312311

313-
const pos = this.pos;
312+
this.view.setInt32(this.pos, value);
314313
this.pos += 4;
315-
this.view.setInt32(pos, value);
316314
}
317315

318316
writeF64(value: number) {
319317
this.ensureBufferSizeToWrite(8);
320318

321-
const pos = this.pos;
319+
this.view.setFloat64(this.pos, value);
322320
this.pos += 8;
323-
this.view.setFloat64(pos, value);
324321
}
325322

326323
writeU64(value: number) {
327324
this.ensureBufferSizeToWrite(8);
328325

329-
const pos = this.pos;
326+
encodeUint64(value, this.view, this.pos);
330327
this.pos += 8;
331-
encodeUint64(value, this.view, pos);
332328
}
333329

334330
writeI64(value: number) {
335331
this.ensureBufferSizeToWrite(8);
336332

337-
const pos = this.pos;
333+
encodeInt64(value, this.view, this.pos);
338334
this.pos += 8;
339-
encodeInt64(value, this.view, pos);
340335
}
341336
}

0 commit comments

Comments
 (0)