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.
@@ -1258,25 +1258,9 @@
1258
1258
  return target.subarray(start, position) // position can change if we call pack again in saveStructures, so we get the buffer now
1259
1259
  } finally {
1260
1260
  if (structures) {
1261
- if (serializationsSinceTransitionRebuild < 10)
1262
- serializationsSinceTransitionRebuild++;
1263
- let sharedLength = structures.sharedLength || 0;
1264
- if (structures.length > sharedLength && !isSequential)
1265
- structures.length = sharedLength;
1266
- if (transitionsCount > 10000) {
1267
- // force a rebuild occasionally after a lot of transitions so it can get cleaned up
1268
- structures.transitions = null;
1269
- serializationsSinceTransitionRebuild = 0;
1270
- transitionsCount = 0;
1271
- if (recordIdsToRemove.length > 0)
1272
- recordIdsToRemove = [];
1273
- } else if (recordIdsToRemove.length > 0 && !isSequential) {
1274
- for (let i = 0, l = recordIdsToRemove.length; i < l; i++) {
1275
- recordIdsToRemove[i][RECORD_SYMBOL] = 0;
1276
- }
1277
- recordIdsToRemove = [];
1278
- }
1261
+ resetStructures();
1279
1262
  if (hasSharedUpdate && packr.saveStructures) {
1263
+ let sharedLength = structures.sharedLength || 0;
1280
1264
  // we can't rely on start/end with REUSE_BUFFER_MODE since they will (probably) change when we save
1281
1265
  let returnBuffer = target.subarray(start, position);
1282
1266
  let newSharedData = prepareStructures(structures, packr);
@@ -1292,6 +1276,26 @@
1292
1276
  position = start;
1293
1277
  }
1294
1278
  };
1279
+ const resetStructures = () => {
1280
+ if (serializationsSinceTransitionRebuild < 10)
1281
+ serializationsSinceTransitionRebuild++;
1282
+ let sharedLength = structures.sharedLength || 0;
1283
+ if (structures.length > sharedLength && !isSequential)
1284
+ structures.length = sharedLength;
1285
+ if (transitionsCount > 10000) {
1286
+ // force a rebuild occasionally after a lot of transitions so it can get cleaned up
1287
+ structures.transitions = null;
1288
+ serializationsSinceTransitionRebuild = 0;
1289
+ transitionsCount = 0;
1290
+ if (recordIdsToRemove.length > 0)
1291
+ recordIdsToRemove = [];
1292
+ } else if (recordIdsToRemove.length > 0 && !isSequential) {
1293
+ for (let i = 0, l = recordIdsToRemove.length; i < l; i++) {
1294
+ recordIdsToRemove[i][RECORD_SYMBOL] = 0;
1295
+ }
1296
+ recordIdsToRemove = [];
1297
+ }
1298
+ };
1295
1299
  const packArray = (value) => {
1296
1300
  var length = value.length;
1297
1301
  if (length < 0x10) {
@@ -1741,8 +1745,9 @@
1741
1745
  }
1742
1746
  // now write the values
1743
1747
  for (let key in object)
1744
- if (safePrototype || object.hasOwnProperty(key))
1748
+ if (safePrototype || object.hasOwnProperty(key)) {
1745
1749
  pack(object[key]);
1750
+ }
1746
1751
  };
1747
1752
 
1748
1753
  // craete reference to useRecords if useRecords is a function
@@ -1861,6 +1866,7 @@
1861
1866
  position = newPosition;
1862
1867
  let startTarget = target;
1863
1868
  pack(value);
1869
+ resetStructures();
1864
1870
  if (startTarget !== target) {
1865
1871
  return { position, targetView, target }; // indicate the buffer was re-allocated
1866
1872
  }