OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <!-- | 2 <!-- |
3 Copyright 2016 The Chromium Authors. All rights reserved. | 3 Copyright 2016 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 <!-- | 8 <!-- |
9 Include all Diagnostic subclasses here so that DiagnosticMap.addDicts() and | 9 Include all Diagnostic subclasses here so that DiagnosticMap.addDicts() and |
10 DiagnosticMap.fromDict() always have access to all subclasses in the | 10 DiagnosticMap.fromDict() always have access to all subclasses in the |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 } | 106 } |
107 | 107 |
108 static fromDict(d) { | 108 static fromDict(d) { |
109 const diagnostics = new DiagnosticMap(); | 109 const diagnostics = new DiagnosticMap(); |
110 diagnostics.addDicts(d); | 110 diagnostics.addDicts(d); |
111 return diagnostics; | 111 return diagnostics; |
112 } | 112 } |
113 | 113 |
114 static fromObject(obj) { | 114 static fromObject(obj) { |
115 const diagnostics = new DiagnosticMap(); | 115 const diagnostics = new DiagnosticMap(); |
116 for (const [name, diagnostic] of Object.entries(obj)) { | 116 if (!(obj instanceof Map)) obj = Object.entries(obj); |
| 117 for (const [name, diagnostic] of obj) { |
117 diagnostics.set(name, diagnostic); | 118 diagnostics.set(name, diagnostic); |
118 } | 119 } |
119 return diagnostics; | 120 return diagnostics; |
120 } | 121 } |
121 | 122 |
122 addDiagnostics(other) { | 123 addDiagnostics(other) { |
123 for (const [name, otherDiagnostic] of other) { | 124 for (const [name, otherDiagnostic] of other) { |
124 if (name === tr.v.d.RESERVED_NAMES.MERGED_FROM || | 125 if (name === tr.v.d.RESERVED_NAMES.GROUPING_PATH) { |
125 name === tr.v.d.RESERVED_NAMES.MERGED_TO || | |
126 name === tr.v.d.RESERVED_NAMES.GROUPING_PATH) { | |
127 continue; | 126 continue; |
128 } | 127 } |
129 | 128 |
130 const myDiagnostic = this.get(name); | 129 const myDiagnostic = this.get(name); |
131 | 130 |
132 if (myDiagnostic !== undefined && | 131 if (myDiagnostic !== undefined && |
133 myDiagnostic.canAddDiagnostic(otherDiagnostic)) { | 132 myDiagnostic.canAddDiagnostic(otherDiagnostic)) { |
134 myDiagnostic.addDiagnostic(otherDiagnostic); | 133 myDiagnostic.addDiagnostic(otherDiagnostic); |
135 continue; | 134 continue; |
136 } | 135 } |
(...skipping 20 matching lines...) Expand all Loading... |
157 this.set(name, clone); | 156 this.set(name, clone); |
158 continue; | 157 continue; |
159 } | 158 } |
160 | 159 |
161 // Now, |myDiagnostic| exists and it is unmergeable with |clone|, which | 160 // Now, |myDiagnostic| exists and it is unmergeable with |clone|, which |
162 // is safe to store in |this|. | 161 // is safe to store in |this|. |
163 this.set(name, new tr.v.d.UnmergeableDiagnosticSet( | 162 this.set(name, new tr.v.d.UnmergeableDiagnosticSet( |
164 [myDiagnostic, clone])); | 163 [myDiagnostic, clone])); |
165 } | 164 } |
166 } | 165 } |
167 | |
168 /** | |
169 * RelatedHistogram diagnostics cannot be merged when Histograms are merged | |
170 * because the related Histograms might not exist yet. | |
171 * This method assumes that all related Histograms exist and that duplicate | |
172 * Diagnostics have been deduplicated. | |
173 * | |
174 * @param {!tr.v.Histogram} parentHist | |
175 */ | |
176 mergeRelationships(parentHist) { | |
177 for (const [name, diagnostic] of this) { | |
178 if (!(diagnostic instanceof tr.v.d.RelatedHistogramMap) && | |
179 !(diagnostic instanceof tr.v.d.RelatedHistogramBreakdown) && | |
180 !(diagnostic instanceof tr.v.d.UnmergeableDiagnosticSet)) { | |
181 continue; | |
182 } | |
183 | |
184 for (const [unusedName, otherHist] of | |
185 this.get(tr.v.d.RESERVED_NAMES.MERGED_FROM)) { | |
186 const otherDiagnostic = otherHist.diagnostics.get(name); | |
187 if (!(otherDiagnostic instanceof tr.v.d.RelatedHistogramMap) && | |
188 !(otherDiagnostic instanceof tr.v.d.RelatedHistogramBreakdown) && | |
189 !(otherDiagnostic instanceof tr.v.d.UnmergeableDiagnosticSet)) { | |
190 continue; | |
191 } | |
192 diagnostic.mergeRelationships(otherDiagnostic, parentHist, otherHist); | |
193 } | |
194 } | |
195 } | |
196 } | 166 } |
197 | 167 |
198 return { | 168 return { |
199 DiagnosticMap, | 169 DiagnosticMap, |
200 }; | 170 }; |
201 }); | 171 }); |
202 </script> | 172 </script> |
OLD | NEW |