msgpackr 1.9.6 → 1.9.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "msgpackr",
3
3
  "author": "Kris Zyp",
4
- "version": "1.9.6",
4
+ "version": "1.9.7",
5
5
  "description": "Ultra-fast MessagePack implementation with extensions for records and structured cloning",
6
6
  "license": "MIT",
7
7
  "types": "./index.d.ts",
package/struct.js CHANGED
@@ -132,25 +132,28 @@ function writeStruct(object, target, position, structures, makeRoom, pack, packr
132
132
  switch (typeof value) {
133
133
  case 'number':
134
134
  let number = value;
135
- if (number >> 0 === number && number < 0x20000000 && number > -0x1f000000) {
136
- if (number < 0xf6 && number >= 0 && (nextTransition.num8 || number < 0x20 && !nextTransition.num32)) {
137
- transition = nextTransition.num8 || createTypeTransition(nextTransition, NUMBER, 1);
138
- target[position++] = number;
139
- } else {
140
- transition = nextTransition.num32 || createTypeTransition(nextTransition, NUMBER, 4);
141
- targetView.setUint32(position, number, true);
142
- position += 4;
143
- }
144
- break;
145
- } else if (number < 0x100000000 && number >= -0x80000000) {
146
- targetView.setFloat32(position, number, true);
147
- if (float32Headers[target[position + 3] >>> 5]) {
148
- let xShifted
149
- // this checks for rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
150
- if (((xShifted = number * mult10[((target[position + 3] & 0x7f) << 1) | (target[position + 2] >> 7)]) >> 0) === xShifted) {
135
+ // first check to see if we are using a lot of ids and should default to wide/common format
136
+ if (nextId < 200 || !nextTransition.num64) {
137
+ if (number >> 0 === number && number < 0x20000000 && number > -0x1f000000) {
138
+ if (number < 0xf6 && number >= 0 && (nextTransition.num8 && !(nextId > 200 && nextTransition.num32) || number < 0x20 && !nextTransition.num32)) {
139
+ transition = nextTransition.num8 || createTypeTransition(nextTransition, NUMBER, 1);
140
+ target[position++] = number;
141
+ } else {
151
142
  transition = nextTransition.num32 || createTypeTransition(nextTransition, NUMBER, 4);
143
+ targetView.setUint32(position, number, true);
152
144
  position += 4;
153
- break;
145
+ }
146
+ break;
147
+ } else if (number < 0x100000000 && number >= -0x80000000) {
148
+ targetView.setFloat32(position, number, true);
149
+ if (float32Headers[target[position + 3] >>> 5]) {
150
+ let xShifted
151
+ // this checks for rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
152
+ if (((xShifted = number * mult10[((target[position + 3] & 0x7f) << 1) | (target[position + 2] >> 7)]) >> 0) === xShifted) {
153
+ transition = nextTransition.num32 || createTypeTransition(nextTransition, NUMBER, 4);
154
+ position += 4;
155
+ break;
156
+ }
154
157
  }
155
158
  }
156
159
  }