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

Side by Side 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: Don't access TextDecoder through 'window' (d8) Created 4 years, 9 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 unified diff | Download patch
« no previous file with comments | « no previous file | tracing/tracing/extras/importer/gzip_importer_test.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <!-- 2 <!--
3 Copyright (c) 2013 The Chromium Authors. All rights reserved. 3 Copyright (c) 2013 The Chromium Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style license that can be 4 Use of this source code is governed by a BSD-style license that can be
5 found in the LICENSE file. 5 found in the LICENSE file.
6 --> 6 -->
7 7
8 <link rel="import" href="/tracing/extras/importer/jszip.html"> 8 <link rel="import" href="/tracing/extras/importer/jszip.html">
9 <link rel="import" href="/tracing/importer/importer.html"> 9 <link rel="import" href="/tracing/importer/importer.html">
10 <link rel="import" href="/tracing/model/model.html"> 10 <link rel="import" href="/tracing/model/model.html">
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 if (have_file_name) 106 if (have_file_name)
107 skipZeroTerminatedString(); 107 skipZeroTerminatedString();
108 if (have_comment) 108 if (have_comment)
109 skipZeroTerminatedString(); 109 skipZeroTerminatedString();
110 if (have_header_crc) 110 if (have_header_crc)
111 getWord(); 111 getWord();
112 112
113 // Inflate the data using jszip. 113 // Inflate the data using jszip.
114 var inflated_data = 114 var inflated_data =
115 JSZip.compressions['DEFLATE'].uncompress(data.subarray(position)); 115 JSZip.compressions['DEFLATE'].uncompress(data.subarray(position));
116 return JSZip.utils.transformTo('string', inflated_data); 116 return GzipImporter.transformToString(inflated_data);
117 }, 117 };
118
119 /**
120 * Transforms an array-like object to a string.
121 *
122 * Note that the following two expressions yield identical results:
123 *
124 * GzipImporter.transformToString_(data)
125 * JSZip.utils.transformTo('string', data)
126 *
127 * We use a custom static method because it is faster and, more importantly,
128 * avoids OOMing on large traces. See
129 * https://github.com/catapult-project/catapult/issues/2051.
130 */
131 GzipImporter.transformToString = function(data) {
132 if (typeof TextDecoder === 'undefined') {
133 // Fall back to jszip if TextDecoder is not available.
134 return JSZip.utils.transformTo('string', data);
135 }
136
137 var type = JSZip.utils.getTypeOf(data);
138 if (type === 'string')
139 return data; // We already have a string.
140
141 if (type === 'array') {
142 // TextDecoder requires an ArrayBuffer or an ArrayBufferView.
143 data = new Uint8Array(data);
144 }
145
146 var decoder = new TextDecoder('utf-8');
147 return decoder.decode(data);
148 };
118 149
119 GzipImporter.prototype = { 150 GzipImporter.prototype = {
120 __proto__: tr.importer.Importer.prototype, 151 __proto__: tr.importer.Importer.prototype,
121 152
122 get importerName() { 153 get importerName() {
123 return 'GzipImporter'; 154 return 'GzipImporter';
124 }, 155 },
125 156
126 /** 157 /**
127 * Called by the Model to check whether the importer just encapsulates 158 * Called by the Model to check whether the importer just encapsulates
(...skipping 13 matching lines...) Expand all
141 } 172 }
142 }; 173 };
143 174
144 tr.importer.Importer.register(GzipImporter); 175 tr.importer.Importer.register(GzipImporter);
145 176
146 return { 177 return {
147 GzipImporter: GzipImporter 178 GzipImporter: GzipImporter
148 }; 179 };
149 }); 180 });
150 </script> 181 </script>
OLDNEW
« no previous file with comments | « no previous file | tracing/tracing/extras/importer/gzip_importer_test.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698