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

Side by Side Diff: tracing/tracing/extras/importer/trace_code_map.html

Issue 2771723003: [tracing] Move math utilities from base into their own subdirectory (attempt 2) (Closed)
Patch Set: rebase Created 3 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
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <!-- 2 <!--
3 Copyright 2015 The Chromium Authors. All rights reserved. 3 Copyright 2015 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/trace_code_entry.html'> 8 <link rel='import' href='/tracing/extras/importer/trace_code_entry.html'>
9 9
10 <script> 10 <script>
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 this.entries_ = []; 73 this.entries_ = [];
74 } 74 }
75 75
76 TraceCodeBank.prototype = { 76 TraceCodeBank.prototype = {
77 removeEntry: function(address) { 77 removeEntry: function(address) {
78 // findLowIndexInSortedArray returns 1 for empty. Just handle the 78 // findLowIndexInSortedArray returns 1 for empty. Just handle the
79 // empty list and bail early. 79 // empty list and bail early.
80 if (this.entries_.length === 0) 80 if (this.entries_.length === 0)
81 return undefined; 81 return undefined;
82 82
83 var index = tr.b.findLowIndexInSortedArray( 83 var index = tr.b.math.findLowIndexInSortedArray(
84 this.entries_, function(entry) { return entry.address; }, address); 84 this.entries_, function(entry) { return entry.address; }, address);
85 var entry = this.entries_[index]; 85 var entry = this.entries_[index];
86 if (!entry || entry.address !== address) 86 if (!entry || entry.address !== address)
87 return undefined; 87 return undefined;
88 88
89 this.entries_.splice(index, 1); 89 this.entries_.splice(index, 1);
90 return entry; 90 return entry;
91 }, 91 },
92 92
93 lookupEntry: function(address) { 93 lookupEntry: function(address) {
94 var index = tr.b.findHighIndexInSortedArray( 94 var index = tr.b.math.findHighIndexInSortedArray(
95 this.entries_, function(e) { return address - e.address; }) - 1; 95 this.entries_, function(e) { return address - e.address; }) - 1;
96 var entry = this.entries_[index]; 96 var entry = this.entries_[index];
97 return entry && 97 return entry &&
98 address < entry.address + entry.size ? entry : undefined; 98 address < entry.address + entry.size ? entry : undefined;
99 }, 99 },
100 100
101 addEntry: function(newEntry) { 101 addEntry: function(newEntry) {
102 // findLowIndexInSortedArray returns 1 for empty list. Just push the 102 // findLowIndexInSortedArray returns 1 for empty list. Just push the
103 // new address as it's the only item. 103 // new address as it's the only item.
104 if (this.entries_.length === 0) 104 if (this.entries_.length === 0)
105 this.entries_.push(newEntry); 105 this.entries_.push(newEntry);
106 106
107 var endAddress = newEntry.address + newEntry.size; 107 var endAddress = newEntry.address + newEntry.size;
108 var lastIndex = tr.b.findLowIndexInSortedArray( 108 var lastIndex = tr.b.math.findLowIndexInSortedArray(
109 this.entries_, function(entry) { return entry.address; }, endAddress); 109 this.entries_, function(entry) { return entry.address; }, endAddress);
110 var index; 110 var index;
111 for (index = lastIndex - 1; index >= 0; --index) { 111 for (index = lastIndex - 1; index >= 0; --index) {
112 var entry = this.entries_[index]; 112 var entry = this.entries_[index];
113 var entryEndAddress = entry.address + entry.size; 113 var entryEndAddress = entry.address + entry.size;
114 if (entryEndAddress <= newEntry.address) 114 if (entryEndAddress <= newEntry.address)
115 break; 115 break;
116 } 116 }
117 ++index; 117 ++index;
118 this.entries_.splice(index, lastIndex - index, newEntry); 118 this.entries_.splice(index, lastIndex - index, newEntry);
119 } 119 }
120 }; 120 };
121 121
122 return { 122 return {
123 TraceCodeMap, 123 TraceCodeMap,
124 }; 124 };
125 }); 125 });
126 126
127 </script> 127 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698