Skip to content

Commit 9579939

Browse files
committed
v8: replace if with switch statements
1 parent 24c362f commit 9579939

File tree

1 file changed

+33
-28
lines changed

1 file changed

+33
-28
lines changed

lib/v8.js

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -247,37 +247,42 @@ Deserializer.prototype.readRawBytes = function readRawBytes(length) {
247247

248248
function arrayBufferViewTypeToIndex(abView) {
249249
const type = ObjectPrototypeToString(abView);
250-
if (type === '[object Int8Array]') return 0;
251-
if (type === '[object Uint8Array]') return 1;
252-
if (type === '[object Uint8ClampedArray]') return 2;
253-
if (type === '[object Int16Array]') return 3;
254-
if (type === '[object Uint16Array]') return 4;
255-
if (type === '[object Int32Array]') return 5;
256-
if (type === '[object Uint32Array]') return 6;
257-
if (type === '[object Float32Array]') return 7;
258-
if (type === '[object Float64Array]') return 8;
259-
if (type === '[object DataView]') return 9;
260-
// Index 10 is FastBuffer.
261-
if (type === '[object BigInt64Array]') return 11;
262-
if (type === '[object BigUint64Array]') return 12;
263-
return -1;
250+
251+
switch (type) {
252+
case '[object Int8Array]': return 0;
253+
case '[object Uint8Array]': return 1;
254+
case '[object Uint8ClampedArray]': return 2;
255+
case '[object Int16Array]': return 3;
256+
case '[object Uint16Array]': return 4;
257+
case '[object Int32Array]': return 5;
258+
case '[object Uint32Array]': return 6;
259+
case '[object Float32Array]': return 7;
260+
case '[object Float64Array]': return 8;
261+
case '[object DataView]': return 9;
262+
// Index 10 is FastBuffer.
263+
case '[object BigInt64Array]': return 11;
264+
case '[object BigUint64Array]': return 12;
265+
default: return -1;
266+
}
264267
}
265268

266269
function arrayBufferViewIndexToType(index) {
267-
if (index === 0) return Int8Array;
268-
if (index === 1) return Uint8Array;
269-
if (index === 2) return Uint8ClampedArray;
270-
if (index === 3) return Int16Array;
271-
if (index === 4) return Uint16Array;
272-
if (index === 5) return Int32Array;
273-
if (index === 6) return Uint32Array;
274-
if (index === 7) return Float32Array;
275-
if (index === 8) return Float64Array;
276-
if (index === 9) return DataView;
277-
if (index === 10) return FastBuffer;
278-
if (index === 11) return BigInt64Array;
279-
if (index === 12) return BigUint64Array;
280-
return undefined;
270+
switch (index) {
271+
case 0: return Int8Array;
272+
case 1: return Uint8Array;
273+
case 2: return Uint8ClampedArray;
274+
case 3: return Int16Array;
275+
case 4: return Uint16Array;
276+
case 5: return Int32Array;
277+
case 6: return Uint32Array;
278+
case 7: return Float32Array;
279+
case 8: return Float64Array;
280+
case 9: return DataView;
281+
case 10: return FastBuffer;
282+
case 11: return BigInt64Array;
283+
case 12: return BigUint64Array;
284+
default: return undefined;
285+
}
281286
}
282287

283288
class DefaultSerializer extends Serializer {

0 commit comments

Comments
 (0)