diff --git a/static_core/plugins/ets/stdlib/escompat/json.ets b/static_core/plugins/ets/stdlib/escompat/json.ets index dfdd97669cd9314964dd69ab769574470f2d65f8..66c598c550083a821a8cb868846603d61bca53f0 100644 --- a/static_core/plugins/ets/stdlib/escompat/json.ets +++ b/static_core/plugins/ets/stdlib/escompat/json.ets @@ -592,6 +592,7 @@ class JSONWriter { private readonly path = new Set() private buffer = new StringBuilder() + private cachedStrings = new Map() constructor(replacer?: (key: String, value: NullishType) => NullishType, space?: String) { this.replacer = replacer @@ -629,7 +630,13 @@ class JSONWriter { } else if (obj === undefined) { this.buffer.append("undefined") } else if (obj instanceof String) { - this.buffer.append(JSON.stringify(obj as String)) + let key = obj as String + let value: String | undefined = this.cachedStrings.get(key) + if (value == undefined) { + value = JSON.stringify(key) + this.cachedStrings.set(key, value) + } + this.buffer.append(value) } else if (obj instanceof RegExpExecArray) { this.buffer.append(JSON.stringify((obj as RegExpExecArray).result)) } else if(obj instanceof Tuple) {