msgpackr 1.9.5 → 1.9.6

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/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
- if (serializationsSinceTransitionRebuild < 10)
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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "msgpackr",
3
3
  "author": "Kris Zyp",
4
- "version": "1.9.5",
4
+ "version": "1.9.6",
5
5
  "description": "Ultra-fast MessagePack implementation with extensions for records and structured cloning",
6
6
  "license": "MIT",
7
7
  "types": "./index.d.ts",