-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[lldb] Return index of element in ValueObject path instead of the element's value #74413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -398,13 +398,16 @@ ValueObject::GetChildAtIndexPath(llvm::ArrayRef<size_t> idxs, | |
if (idxs.size() == 0) | ||
return GetSP(); | ||
ValueObjectSP root(GetSP()); | ||
|
||
size_t current_index = 0; | ||
for (size_t idx : idxs) { | ||
root = root->GetChildAtIndex(idx); | ||
if (!root) { | ||
if (index_of_error) | ||
*index_of_error = idx; | ||
*index_of_error = current_index; | ||
return root; | ||
} | ||
current_index += 1; | ||
} | ||
return root; | ||
} | ||
|
@@ -414,13 +417,17 @@ lldb::ValueObjectSP ValueObject::GetChildAtIndexPath( | |
if (idxs.size() == 0) | ||
return GetSP(); | ||
ValueObjectSP root(GetSP()); | ||
|
||
size_t current_index = 0; | ||
for (std::pair<size_t, bool> idx : idxs) { | ||
root = root->GetChildAtIndex(idx.first, idx.second); | ||
if (!root) { | ||
if (index_of_error) | ||
*index_of_error = idx.first; | ||
*index_of_error = current_index; | ||
return root; | ||
} | ||
|
||
current_index += 1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe I'll use the pre-increment operator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note this guideline is about pre vs post (not about +=1), and it refers to iterators mostly. I don't think you need to change anything here! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, but if we're not going with Or are you saying we should just stick with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I'll just stick with |
||
} | ||
return root; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the tiniest nit on earth but
current_index++
here to increment this?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure!
I had a hunch someone would point this one out, but I thought it'd be fun to see who, if anyone, would.
You passed the test! 😂
Personally, I prefer
+= 1
because:++
operator.+= 1
more explicitly communicates my intent.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After reading the Swift rationale for removing the
++
operator I understand why you'd use+= 1
instead.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I take it you're referring to Swift evolution's proposal 0004 - Remove the
++
and--
operators.As a coding and computer science mentor and writer, I naturally agree with Chris Lattner in that any code I write may serves as potential educational material to the reader/maintainer. For me, there are more cons than pros to the pre- and post-increment operators when I look at them through an educational lens.