msgpackr 1.9.5 → 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/dist/index-no-eval.cjs +25 -19
- package/dist/index-no-eval.cjs.map +1 -1
- package/dist/index-no-eval.min.js +1 -1
- package/dist/index-no-eval.min.js.map +1 -1
- package/dist/index.js +25 -19
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/node.cjs +45 -36
- package/dist/node.cjs.map +1 -1
- package/dist/test.js +45 -36
- package/dist/test.js.map +1 -1
- package/pack.js +25 -19
- package/package.json +1 -1
- package/struct.js +20 -17
package/pack.js
CHANGED
|
@@ -172,25 +172,9 @@ export class Packr extends Unpackr {
|
|
|
172
172
|
return target.subarray(start, position) // position can change if we call pack again in saveStructures, so we get the buffer now
|
|
173
173
|
} finally {
|
|
174
174
|
if (structures) {
|
|
175
|
-
|
|
176
|
-
serializationsSinceTransitionRebuild++
|
|
177
|
-
let sharedLength = structures.sharedLength || 0
|
|
178
|
-
if (structures.length > sharedLength && !isSequential)
|
|
179
|
-
structures.length = sharedLength
|
|
180
|
-
if (transitionsCount > 10000) {
|
|
181
|
-
// force a rebuild occasionally after a lot of transitions so it can get cleaned up
|
|
182
|
-
structures.transitions = null
|
|
183
|
-
serializationsSinceTransitionRebuild = 0
|
|
184
|
-
transitionsCount = 0
|
|
185
|
-
if (recordIdsToRemove.length > 0)
|
|
186
|
-
recordIdsToRemove = []
|
|
187
|
-
} else if (recordIdsToRemove.length > 0 && !isSequential) {
|
|
188
|
-
for (let i = 0, l = recordIdsToRemove.length; i < l; i++) {
|
|
189
|
-
recordIdsToRemove[i][RECORD_SYMBOL] = 0
|
|
190
|
-
}
|
|
191
|
-
recordIdsToRemove = []
|
|
192
|
-
}
|
|
175
|
+
resetStructures();
|
|
193
176
|
if (hasSharedUpdate && packr.saveStructures) {
|
|
177
|
+
let sharedLength = structures.sharedLength || 0
|
|
194
178
|
// we can't rely on start/end with REUSE_BUFFER_MODE since they will (probably) change when we save
|
|
195
179
|
let returnBuffer = target.subarray(start, position)
|
|
196
180
|
let newSharedData = prepareStructures(structures, packr);
|
|
@@ -206,6 +190,26 @@ export class Packr extends Unpackr {
|
|
|
206
190
|
position = start
|
|
207
191
|
}
|
|
208
192
|
}
|
|
193
|
+
const resetStructures = () => {
|
|
194
|
+
if (serializationsSinceTransitionRebuild < 10)
|
|
195
|
+
serializationsSinceTransitionRebuild++
|
|
196
|
+
let sharedLength = structures.sharedLength || 0
|
|
197
|
+
if (structures.length > sharedLength && !isSequential)
|
|
198
|
+
structures.length = sharedLength
|
|
199
|
+
if (transitionsCount > 10000) {
|
|
200
|
+
// force a rebuild occasionally after a lot of transitions so it can get cleaned up
|
|
201
|
+
structures.transitions = null
|
|
202
|
+
serializationsSinceTransitionRebuild = 0
|
|
203
|
+
transitionsCount = 0
|
|
204
|
+
if (recordIdsToRemove.length > 0)
|
|
205
|
+
recordIdsToRemove = []
|
|
206
|
+
} else if (recordIdsToRemove.length > 0 && !isSequential) {
|
|
207
|
+
for (let i = 0, l = recordIdsToRemove.length; i < l; i++) {
|
|
208
|
+
recordIdsToRemove[i][RECORD_SYMBOL] = 0
|
|
209
|
+
}
|
|
210
|
+
recordIdsToRemove = []
|
|
211
|
+
}
|
|
212
|
+
}
|
|
209
213
|
const packArray = (value) => {
|
|
210
214
|
var length = value.length
|
|
211
215
|
if (length < 0x10) {
|
|
@@ -655,8 +659,9 @@ export class Packr extends Unpackr {
|
|
|
655
659
|
}
|
|
656
660
|
// now write the values
|
|
657
661
|
for (let key in object)
|
|
658
|
-
if (safePrototype || object.hasOwnProperty(key))
|
|
662
|
+
if (safePrototype || object.hasOwnProperty(key)) {
|
|
659
663
|
pack(object[key])
|
|
664
|
+
}
|
|
660
665
|
}
|
|
661
666
|
|
|
662
667
|
// craete reference to useRecords if useRecords is a function
|
|
@@ -775,6 +780,7 @@ export class Packr extends Unpackr {
|
|
|
775
780
|
position = newPosition;
|
|
776
781
|
let startTarget = target;
|
|
777
782
|
pack(value);
|
|
783
|
+
resetStructures();
|
|
778
784
|
if (startTarget !== target) {
|
|
779
785
|
return { position, targetView, target }; // indicate the buffer was re-allocated
|
|
780
786
|
}
|
package/package.json
CHANGED
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
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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
|
-
|
|
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
|
}
|