mirror of
https://github.com/zen-browser/desktop.git
synced 2026-08-21 06:00:49 +00:00
gh-10649: Implement JSON store length hints (gh-13260)
This commit is contained in:
29
src/toolkit/modules/JSONFile-sys-mjs.patch
Normal file
29
src/toolkit/modules/JSONFile-sys-mjs.patch
Normal file
@@ -0,0 +1,29 @@
|
||||
diff --git a/toolkit/modules/JSONFile.sys.mjs b/toolkit/modules/JSONFile.sys.mjs
|
||||
index 397991e4af8f49b6365d729fc11267b5c1113400..1955b7ff1d428e891f5ef066e7a4ac25aa5ec9b4 100644
|
||||
--- a/toolkit/modules/JSONFile.sys.mjs
|
||||
+++ b/toolkit/modules/JSONFile.sys.mjs
|
||||
@@ -132,6 +132,7 @@ export function JSONFile(config) {
|
||||
this._finalizeInternalBound,
|
||||
() => ({ sanitizedBasename: this.sanitizedBasename })
|
||||
);
|
||||
+ this._useSizeHints = config.useSizeHints ?? false;
|
||||
}
|
||||
|
||||
JSONFile.prototype = {
|
||||
@@ -423,11 +424,15 @@ JSONFile.prototype = {
|
||||
}
|
||||
|
||||
try {
|
||||
- await IOUtils.writeJSON(
|
||||
+ if (this._useSizeHints && this._lastSavedSize) {
|
||||
+ this._options.lengthHint = this._lastSavedSize;
|
||||
+ }
|
||||
+ const result = await IOUtils.writeJSON(
|
||||
this.path,
|
||||
this._data,
|
||||
Object.assign({ tmpPath: this.path + ".tmp" }, this._options)
|
||||
);
|
||||
+ this._lastSavedSize = this._useSizeHints ? result.jsonLength : null;
|
||||
} catch (ex) {
|
||||
if (typeof this._data.toJSONSafe == "function") {
|
||||
// If serialization fails, try fallback safe JSON converter.
|
||||
Reference in New Issue
Block a user