Convert some Args index-based iteration to range-style iteration.

This is better for a number of reasons.  Mostly style, but also:

1) Signed-unsigned comparison warnings disappear since there is
   no loop index.
2) Iterating with the range-for style gives you back an entry
   that has more than just a const char*, so it's more efficient
   and more useful.
3) Makes code safter since the type system enforces that it's
   impossible to index out of bounds.

llvm-svn: 283413
This commit is contained in:
Zachary Turner
2016-10-05 23:40:23 +00:00
parent 3b564e9765
commit 97d2c4011b
18 changed files with 240 additions and 252 deletions

View File

@@ -770,28 +770,22 @@ public:
process->GetThreadList().GetMutex());
const uint32_t num_threads = process->GetThreadList().GetSize();
std::vector<Thread *> resume_threads;
for (uint32_t i = 0; i < argc; ++i) {
bool success;
const int base = 0;
uint32_t thread_idx =
StringConvert::ToUInt32(command.GetArgumentAtIndex(i),
LLDB_INVALID_INDEX32, base, &success);
if (success) {
Thread *thread =
process->GetThreadList().FindThreadByIndexID(thread_idx).get();
if (thread) {
resume_threads.push_back(thread);
} else {
result.AppendErrorWithFormat("invalid thread index %u.\n",
thread_idx);
result.SetStatus(eReturnStatusFailed);
return false;
}
} else {
for (auto &entry : command.entries()) {
uint32_t thread_idx;
if (entry.ref.getAsInteger(0, thread_idx)) {
result.AppendErrorWithFormat(
"invalid thread index argument: \"%s\".\n",
command.GetArgumentAtIndex(i));
"invalid thread index argument: \"%s\".\n", entry.c_str());
result.SetStatus(eReturnStatusFailed);
return false;
}
Thread *thread =
process->GetThreadList().FindThreadByIndexID(thread_idx).get();
if (thread) {
resume_threads.push_back(thread);
} else {
result.AppendErrorWithFormat("invalid thread index %u.\n",
thread_idx);
result.SetStatus(eReturnStatusFailed);
return false;
}