diff options
author | Alon Zakai <azakai@mozilla.com> | 2010-11-27 14:51:58 -0800 |
---|---|---|
committer | Alon Zakai <azakai@mozilla.com> | 2010-11-27 14:51:58 -0800 |
commit | c3f19a35f46dfc0879862212140867cb1998cc65 (patch) | |
tree | aa1f77aed8ee4609424c872025dc349b1bfcb437 /src/utility.js | |
parent | 1286f8332f1254768a9a2a40e8b1c89b4e8ed944 (diff) |
simplify dump(), avoid memory issues
Diffstat (limited to 'src/utility.js')
-rw-r--r-- | src/utility.js | 13 |
1 files changed, 1 insertions, 12 deletions
diff --git a/src/utility.js b/src/utility.js index fd8a1bce..391efb14 100644 --- a/src/utility.js +++ b/src/utility.js @@ -8,19 +8,8 @@ function safeQuote(x) { function dump(item) { var CHUNK = 500; function lineify(text) { - var ret = ''; - while (text.length > 0) { - if (text.length < CHUNK) { - ret += text; - return ret; - } - var subText = text.substring(CHUNK-20, CHUNK); - var index = CHUNK-19+Math.max(subText.indexOf(','), subText.indexOf(']'), subText.indexOf('}'), 21); - ret += text.substr(0,index) + '\n'; - text = '// ' + text.substr(index); - } + return text.replace(/.{80}/g, '$&\n'); } - try { return lineify(JSON.stringify(item)); } catch(e) { |