what-the-pack
Advanced tools
Comparing version 1.1.3 to 1.1.4
@@ -0,1 +1,3 @@ | ||
/* eslint-disable no-console */ | ||
const Benchmark = require('benchmark'); | ||
@@ -38,9 +40,2 @@ const suite = new Benchmark.Suite; | ||
} | ||
const map = (length) => { | ||
const result = {}; | ||
for (let i = 0; i < length; i++) { | ||
result[i + ''] = i; | ||
} | ||
return result; | ||
} | ||
@@ -47,0 +42,0 @@ const medium = { |
50
index.js
@@ -62,3 +62,5 @@ /* eslint-disable no-console */ | ||
case 'string': | ||
if (value.length < 32) { // < 32, fixstr | ||
length = Buffer.byteLength(value); | ||
if (length < 32) { // < 32, fixstr | ||
length = 0; | ||
for (let i = 0, c = 0, l = value.length; i < l; i += 1) { | ||
@@ -98,27 +100,23 @@ c = value.charCodeAt(i); | ||
} | ||
break; | ||
} else { // > 32, str8, str16, str32 | ||
length = Buffer.byteLength(value); | ||
if (length < 256) { // str8 | ||
allocator.buffer[allocator.offset += 1] = 217; | ||
allocator.buffer[allocator.offset += 1] = length; | ||
allocator.buffer.write(value, allocator.offset += 1, length, 'utf8'); | ||
allocator.offset += length - 1; | ||
} else if (length < 65536) { // str16 | ||
allocator.buffer[allocator.offset += 1] = 218; | ||
allocator.buffer[allocator.offset += 1] = length >> 8; | ||
allocator.buffer[allocator.offset += 1] = length; | ||
allocator.buffer.write(value, allocator.offset += 1, length, 'utf8'); | ||
allocator.offset += length - 1; | ||
} else if (length < 4294967296) { // str32 | ||
allocator.buffer[allocator.offset += 1] = 219; | ||
allocator.buffer[allocator.offset += 1] = length >> 24; | ||
allocator.buffer[allocator.offset += 1] = length >> 16; | ||
allocator.buffer[allocator.offset += 1] = length >> 8; | ||
allocator.buffer[allocator.offset += 1] = length; | ||
allocator.buffer.write(value, allocator.offset += 1, length, 'utf8'); | ||
allocator.offset += length - 1; | ||
} else { | ||
throw Error('Max supported string length (4294967296) exceeded, encoding failure.'); | ||
} | ||
} else if (length < 256) { // str8 | ||
allocator.buffer[allocator.offset += 1] = 217; | ||
allocator.buffer[allocator.offset += 1] = length; | ||
allocator.buffer.write(value, allocator.offset += 1, length, 'utf8'); | ||
allocator.offset += length - 1; | ||
} else if (length < 65536) { // str16 | ||
allocator.buffer[allocator.offset += 1] = 218; | ||
allocator.buffer[allocator.offset += 1] = length >> 8; | ||
allocator.buffer[allocator.offset += 1] = length; | ||
allocator.buffer.write(value, allocator.offset += 1, length, 'utf8'); | ||
allocator.offset += length - 1; | ||
} else if (length < 4294967296) { // str32 | ||
allocator.buffer[allocator.offset += 1] = 219; | ||
allocator.buffer[allocator.offset += 1] = length >> 24; | ||
allocator.buffer[allocator.offset += 1] = length >> 16; | ||
allocator.buffer[allocator.offset += 1] = length >> 8; | ||
allocator.buffer[allocator.offset += 1] = length; | ||
allocator.buffer.write(value, allocator.offset += 1, length, 'utf8'); | ||
allocator.offset += length - 1; | ||
} else { | ||
throw Error('Max supported string length (4294967296) exceeded, encoding failure.'); | ||
} | ||
@@ -125,0 +123,0 @@ break; |
{ | ||
"name": "what-the-pack", | ||
"version": "1.1.3", | ||
"version": "1.1.4", | ||
"description": "The fastest MessagePack implementation in JS", | ||
@@ -18,5 +18,5 @@ "main": "index.js", | ||
"notepack.io": "^2.1.3", | ||
"rollup": "^0.66.6", | ||
"rollup": "^0.67.4", | ||
"rollup-plugin-commonjs": "^9.2.0", | ||
"rollup-plugin-node-resolve": "^3.4.0", | ||
"rollup-plugin-node-resolve": "^4.0.0", | ||
"rollup-plugin-terser": "^3.0.0" | ||
@@ -23,0 +23,0 @@ }, |
10
test.js
@@ -9,3 +9,3 @@ const { reallocate, encode, decode } = require('./index'); | ||
test('fixstr', () => { | ||
[ '', 'hello' ].forEach((value) => expect(decode(encode(value))).toBe(value)); | ||
[ '', 'hello', 'WALL·E – Typeset in the Future'].forEach((value) => expect(decode(encode(value))).toBe(value)); | ||
}); | ||
@@ -209,10 +209,2 @@ it('str 8', () => { | ||
const map = (length) => { | ||
const result = {}; | ||
for (let i = 0; i < length; i++) { | ||
result[i + ''] = i; | ||
} | ||
return result; | ||
} | ||
const large = { | ||
@@ -219,0 +211,0 @@ unsigned: [1, 2, 3, 4, { b: { c: [128, 256, 65536, 4294967296] } }], |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
388389
1631