msgpackr 1.7.0-alpha3 → 1.7.0-alpha4
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.js +14 -4
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +58 -57
- package/dist/index.min.js.map +1 -1
- package/dist/node.cjs +30 -15
- package/dist/node.cjs.map +1 -1
- package/dist/test.js +30 -15
- package/dist/test.js.map +1 -1
- package/pack.js +14 -6
- package/package.json +1 -1
- package/struct.js +14 -9
- package/unpack.js +2 -0
package/dist/index.js
CHANGED
|
@@ -139,6 +139,8 @@
|
|
|
139
139
|
}
|
|
140
140
|
_mergeStructures(loadedStructures, existingStructures) {
|
|
141
141
|
loadedStructures = loadedStructures || [];
|
|
142
|
+
if (Object.isFrozen(loadedStructures))
|
|
143
|
+
loadedStructures = loadedStructures.map(structure => structure.slice(0));
|
|
142
144
|
for (let i = 0, l = loadedStructures.length; i < l; i++) {
|
|
143
145
|
let structure = loadedStructures[i];
|
|
144
146
|
if (structure) {
|
|
@@ -1187,7 +1189,7 @@
|
|
|
1187
1189
|
if (structures) {
|
|
1188
1190
|
if (serializationsSinceTransitionRebuild < 10)
|
|
1189
1191
|
serializationsSinceTransitionRebuild++;
|
|
1190
|
-
let sharedLength = structures.sharedLength ||
|
|
1192
|
+
let sharedLength = structures.sharedLength || 0;
|
|
1191
1193
|
if (structures.length > sharedLength)
|
|
1192
1194
|
structures.length = sharedLength;
|
|
1193
1195
|
if (transitionsCount > 10000) {
|
|
@@ -1206,10 +1208,9 @@
|
|
|
1206
1208
|
if (hasSharedUpdate && packr.saveStructures) {
|
|
1207
1209
|
// we can't rely on start/end with REUSE_BUFFER_MODE since they will (probably) change when we save
|
|
1208
1210
|
let returnBuffer = target.subarray(start, position$1);
|
|
1209
|
-
let newSharedData =
|
|
1210
|
-
if (packr.saveStructures(newSharedData, newSharedData.isCompatible
|
|
1211
|
+
let newSharedData = prepareStructures(structures, packr);
|
|
1212
|
+
if (packr.saveStructures(newSharedData, newSharedData.isCompatible) === false) {
|
|
1211
1213
|
// get updated structures and try again if the update failed
|
|
1212
|
-
packr._mergeStructures(packr.getStructures());
|
|
1213
1214
|
return packr.pack(value)
|
|
1214
1215
|
}
|
|
1215
1216
|
packr.lastNamedStructuresLength = sharedLength;
|
|
@@ -1966,6 +1967,15 @@
|
|
|
1966
1967
|
}
|
|
1967
1968
|
addExtension(extension);
|
|
1968
1969
|
}
|
|
1970
|
+
function prepareStructures(structures, packr) {
|
|
1971
|
+
structures.isCompatible = (existingStructures) => {
|
|
1972
|
+
let compatible = !existingStructures || ((packr.lastNamedStructuresLength || 0) === existingStructures.length);
|
|
1973
|
+
if (!compatible) // we want to merge these existing structures immediately since we already have it and we are in the right transaction
|
|
1974
|
+
packr._mergeStructures(existingStructures);
|
|
1975
|
+
return compatible;
|
|
1976
|
+
};
|
|
1977
|
+
return structures
|
|
1978
|
+
}
|
|
1969
1979
|
|
|
1970
1980
|
let defaultPackr = new Packr({ useRecords: false });
|
|
1971
1981
|
const pack = defaultPackr.pack;
|