-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Simplify implementation of TClass::FindClassOrBaseMethodWithId() #908
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
Conversation
|
Starting build on |
|
@pcanal This isn't really work in progress, I just wanted to test that the build would pass. Actually, if you think this commit is ok, we can merge this now, but please let me merge it myself locally, otherwise the GPG signature on the commit is lost. |
What do you mean? How is that different from other PR?
I am 'slightly' surprised it works in C++11 ... |
|
The GitHub interface strips GPG signatures from the commits. I usually merge on my laptop and push, and that way it's as if I pressed merge, but I can keep the GPG signatures. As for the commit, if you look at the date, you'll see it's from a while ago, when I was working on I/O optimizations. I was just trying to improve readability and test range for with ROOT containers. Yes, it works :-) So, I guess we should be trying to use this more than the usual while loop. What do you think? |
What is the advantage/gain/importance of doing so? |
Indeed, I was confusing with the C++17 features like |
| TFunction *f = GetMethodList()->Get(declId); | ||
| if (f) return (TMethod*)f; | ||
| if (auto method = GetMethodList()->Get(declId)) | ||
| return reinterpret_cast<TMethod *>(method); |
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.
'Thanks' to the auto keyword the validity of the reinterpret_cast becomes harder to Check. (i.e. now one that to find out that GetMethodList returns a TListOfFunctions and then look up the return type of Get ... only then can one know that the cast is okay since TMethod inherits directly for the return type, TFunction).
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.
Well, it must be fine, since that's what the function returns. Using reinterpret_cast is better than just a C cast, as it will fail in more cases where the C cast would compile and give wrong results.
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.
Well, it must be fine,
It is fine of course. My point is about code readability (i.e. the ability for the human reader to verify the code :) ).
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.e. in this case, because of the reinterpret_cast, I would use
if (TFunction *method = GetMethodList()->Get(declId))
return reinterpret_cast<TMethod *>(method);
|
The advantage in keeping GPG signatures is that it tells people that the change came from a trusted source. We should all be doing this, but due to being complicated, I understand that others don't bother. |
| } | ||
| } | ||
| return 0; | ||
| for (auto item : *GetListOfBases()) |
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.
One hesitation I have with this pattern is that the iterator cast is moved one level down. i.e.
while ((item = reinterpret_cast<TBaseClass *>(next()))) {
if (auto base = item->GetClassPointer())
vs
for (auto item : *GetListOfBases())
if (auto base = reinterpret_cast<TBaseClass *>(item)->GetClassPointer())
or more often.
for (auto item : *GetListOfBases()) {
auto base = reinterpret_cast<TBaseClass *>(item);
if (base->GetClassPointer())
I wonder if we can have something like
for (auto item : ContaineeIs<TBaseClass*>(GetListOfBases()))
if (auto base = item->GetClassPointer())
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.
Let's not sidestep a 5 line commit into a lenghty discussion on code patterns. If you disagree that the code is more readable after the changes, just let me know and I'll close the PR.
My points were triggered by your good point:
where I think to be really recommended as the new pattern we should slightly improve on it. Could you, as a subsequent PR, try to improve the collection in the direction I mentioned (assuming you agree it is 'even' better :) Anyway
I agree it is more readable except for the Thanks, |
|
Ok, I will use TFunction instead of auto, then I can merge, then? |
Yes. Thanks. |
|
By improve the collection you mean changing all while loops to range fors? |
Not quite (as this might be a good thing for the code refactoring tool to do). I mean to enable something like: |
|
Sure, I don't know how complicated that may be, but if it's doable, we can try in a later PR. Thanks. |
|
Starting build on |
core/meta/src/TClass.cxx
Outdated
| return 0; | ||
| for (auto item : *GetListOfBases()) | ||
| if (auto base = reinterpret_cast<TBaseClass *>(item)->GetClassPointer()) | ||
| if (auto method = base->FindClassOrBaseMethodWithId(declId)) |
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.
one more TFunction*. Sorry to be a pest :)
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.
Ok, will do, no problem.
|
Starting build on |
|
Build failed on slc6/gcc62. |
|
Build failed on ubuntu14/native. Failing tests: |
|
Build failed on mac1012/native. Failing tests: |
|
Build failed on centos7/gcc49. Failing tests: |
|
Build failed on slc6/gcc49. Errors:
Failing tests: |
"too" is too general and may also match the build path. I could not find "too slow" being printed anywhere, so just check the output for "too inaccurate".
Test PR, do not merge please.