gh-14990: Part 2 - Correctly set length hint for JSON writes (gh-14994)

This commit is contained in:
mr. m
2026-08-16 16:26:48 +02:00
committed by GitHub
parent 93776ce026
commit 82e1c79b60
3 changed files with 7 additions and 6 deletions

View File

@@ -54,7 +54,7 @@ diff --git a/browser/components/sessionstore/SessionWriter.sys.mjs b/browser/com
+ uncompressedBytes = await IOUtils.writeJSON(this.Paths.clean, state, {
tmpPath: this.Paths.clean + ".tmp",
compress: true,
+ jsonLengthHint,
+ lengthHint: jsonLengthHint,
});
fileStat = await IOUtils.stat(this.Paths.clean);
} else if (this.state == STATE_RECOVERY) {
@@ -69,7 +69,7 @@ diff --git a/browser/components/sessionstore/SessionWriter.sys.mjs b/browser/com
tmpPath: this.Paths.recovery + ".tmp",
backupFile: this.Paths.recoveryBackup,
compress: true,
+ jsonLengthHint,
+ lengthHint: jsonLengthHint,
});
fileStat = await IOUtils.stat(this.Paths.recovery);
} else {
@@ -80,7 +80,7 @@ diff --git a/browser/components/sessionstore/SessionWriter.sys.mjs b/browser/com
+ uncompressedBytes = await IOUtils.writeJSON(this.Paths.recovery, state, {
tmpPath: this.Paths.recovery + ".tmp",
compress: true,
+ jsonLengthHint,
+ lengthHint: jsonLengthHint,
});
fileStat = await IOUtils.stat(this.Paths.recovery);
}

View File

@@ -45,7 +45,8 @@
"id": "D298708",
"name": "Issue 14990",
"replaces": {
"this._lastJsonLength = uncompressedBytes;": "this._lastJsonLength = uncompressedBytes.jsonLength;"
"this._lastJsonLength = uncompressedBytes;": "this._lastJsonLength = uncompressedBytes.jsonLength;",
" jsonLengthHint,": " lengthHint: jsonLengthHint,"
}
}
]

View File

@@ -1,5 +1,5 @@
diff --git a/toolkit/modules/JSONFile.sys.mjs b/toolkit/modules/JSONFile.sys.mjs
index 397991e4af8f49b6365d729fc11267b5c1113400..70da83a0dd7658986dfd5f52103873bbb33b3c18 100644
index 397991e4af8f49b6365d729fc11267b5c1113400..599ed16981aa1f1e9abfee2ad6c1883efd88e0ba 100644
--- a/toolkit/modules/JSONFile.sys.mjs
+++ b/toolkit/modules/JSONFile.sys.mjs
@@ -132,6 +132,7 @@ export function JSONFile(config) {
@@ -16,7 +16,7 @@ index 397991e4af8f49b6365d729fc11267b5c1113400..70da83a0dd7658986dfd5f52103873bb
try {
- await IOUtils.writeJSON(
+ if (this._useSizeHints && this._lastSavedSize) {
+ this._options.jsonLengthHint = Math.ceil(this._lastSavedSize * 1.05);
+ this._options.lengthHint = Math.ceil(this._lastSavedSize * 1.05);
+ }
+ const result = await IOUtils.writeJSON(
this.path,