Skip to content

Commit 4b76f89

Browse files
committed
Do in-place filtering of added locs, and cache Vector::Size() when looping
1 parent d7cb86d commit 4b76f89

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

compiler-rt/lib/tsan/rtl/tsan_rtl_report.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -200,22 +200,22 @@ void ScopedReportBase::AddMemoryAccess(uptr addr, uptr external_tag, Shadow s,
200200

201201
void ScopedReportBase::SymbolizeStackElems() {
202202
// symbolize memory ops
203-
for (usize i = 0; i < rep_->mops.Size(); i++) {
203+
for (usize i = 0, size = rep_->mops.Size(); i < size; i++) {
204204
ReportMop *mop = rep_->mops[i];
205205
mop->stack = SymbolizeStack(mop->stack_trace);
206206
if (mop->stack)
207207
mop->stack->suppressable = true;
208208
}
209209

210210
// symbolize locations
211-
for (usize i = 0; i < rep_->locs.Size(); i++) {
211+
for (usize i = 0, size = rep_->locs.Size(); i < size; i++) {
212212
// added locations have a NULL placeholder - don't dereference them
213213
if (ReportLocation *loc = rep_->locs[i])
214214
loc->stack = SymbolizeStackId(loc->stack_id);
215215
}
216216

217217
// symbolize any added locations
218-
for (usize i = 0; i < rep_->added_location_addrs.Size(); i++) {
218+
for (usize i = 0, size = rep_->added_location_addrs.Size(); i < size; i++) {
219219
AddedLocationAddr *added_loc = &rep_->added_location_addrs[i];
220220
if (ReportLocation *loc = SymbolizeData(added_loc->addr)) {
221221
loc->suppressable = true;
@@ -224,24 +224,25 @@ void ScopedReportBase::SymbolizeStackElems() {
224224
}
225225

226226
// Filter out any added location placeholders that could not be symbolized
227-
Vector<ReportLocation *> filtered_locs;
228-
for (usize i = 0; i < rep_->locs.Size(); i++)
229-
if (rep_->locs[i] != nullptr)
230-
filtered_locs.PushBack(rep_->locs[i]);
231-
rep_->locs.Resize(filtered_locs.Size());
232-
for (usize i = 0; i < filtered_locs.Size(); i++)
233-
rep_->locs[i] = (filtered_locs[i]);
227+
usize j = 0;
228+
for (usize i = 0, size = rep_->locs.Size(); i < size; i++) {
229+
if (rep_->locs[i] != nullptr) {
230+
rep_->locs[j] = rep_->locs[i];
231+
j++;
232+
}
233+
}
234+
rep_->locs.Resize(j);
234235

235236
// symbolize threads
236-
for (usize i = 0; i < rep_->threads.Size(); i++) {
237+
for (usize i = 0, size = rep_->threads.Size(); i < size; i++) {
237238
ReportThread *rt = rep_->threads[i];
238239
rt->stack = SymbolizeStackId(rt->stack_id);
239240
if (rt->stack)
240241
rt->stack->suppressable = rt->suppressable;
241242
}
242243

243244
// symbolize mutexes
244-
for (usize i = 0; i < rep_->mutexes.Size(); i++) {
245+
for (usize i = 0, size = rep_->mutexes.Size(); i < size; i++) {
245246
ReportMutex *rm = rep_->mutexes[i];
246247
rm->stack = SymbolizeStackId(rm->stack_id);
247248
}

0 commit comments

Comments
 (0)