Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Unified Diff: tracing/tracing/extras/importer/gzip_importer.html

Issue 1739663003: Use TextDecoder instead of JSZip.utils.transformTo in GzipImporter (Closed) Base URL: git@github.com:catapult-project/catapult.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tracing/tracing/extras/importer/gzip_importer.html
diff --git a/tracing/tracing/extras/importer/gzip_importer.html b/tracing/tracing/extras/importer/gzip_importer.html
index a5dab95d3aa3e02ef9d8ddefeeebe8deaf6c046c..135d8f41b733c44a93879d9d04761900f82be27c 100644
--- a/tracing/tracing/extras/importer/gzip_importer.html
+++ b/tracing/tracing/extras/importer/gzip_importer.html
@@ -113,8 +113,34 @@ tr.exportTo('tr.e.importer', function() {
// Inflate the data using jszip.
var inflated_data =
JSZip.compressions['DEFLATE'].uncompress(data.subarray(position));
- return JSZip.utils.transformTo('string', inflated_data);
- },
+ return GzipImporter.transformToString_(inflated_data);
+ };
+
+ /**
+ * Transforms an array-like object to a string.
+ *
+ * Note that the following two expressions yield identical results:
+ *
+ * GzipImporter.transformToString_(data)
+ * JSZip.utils.transformTo('string', data)
+ *
+ * We use a custom static method because it is faster and, more importantly,
+ * avoids OOMing on large traces. See
+ * https://github.com/catapult-project/catapult/issues/2051.
+ */
+ GzipImporter.transformToString_ = function(data) {
+ var type = JSZip.utils.getTypeOf(data);
Sami 2016/02/25 14:44:54 Is it worth having a fallback to JSZip if TextDeco
petrcermak 2016/02/25 15:22:41 Done.
+ if (type === 'string')
+ return data; // We already have a string.
+
+ if (type === 'array') {
+ // TextDecoder requires an ArrayBuffer or an ArrayBufferView.
+ data = new Uint8Array(data);
+ }
+
+ var decoder = new TextDecoder('utf-8');
+ return decoder.decode(data);
+ };
GzipImporter.prototype = {
__proto__: tr.importer.Importer.prototype,
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698