Thank you for the contribution. It is a good start but I think it needs a bit more work.
I have 3 complaints about this patch:
I don't like the if else chain of calls to GetAttribute. I think it is too expensive to iterate the attributes all these times. I think you should redo the loop from wxXmlNode::GetAttribute:
This will get you to a single iteration. You can get even fancier/faster if you first check for attrName[0]=='v' and then get to the slower/fuller checks in an if else fashion.
I don't like the calls to wxSplit. Hidden calls to new/delete like these are the #1 contributor to slowness in C::B. I think it is possible to write this comparison doing 0 allocations, and iterating the strings 1 or 2 times. And I think it shouldn't be that hard. I think you need to use the wx equivalent of https://en.cppreference.com/w/cpp/string/byte/strtol
If any of the two versions fail to parse as version an error must be reported in the logs. I suppose it is fine you just use the debug log.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Given there is no strtol equivalent in wx I would do the number parsing/conversion manually. Given how much you already have adding a value accumulator and *=10 to it would be fine and probably simpler. I'd probably do it with a separate function like int extractNumber(int *result, const wxString &s, int searchStart); or just inline in this one. Whatever is less code and looks simpler.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Capitalization of local variables. I'd prefer if you use lowercase first letter. No matter what is written in the style guide, the style of cb is mostly lowercase first letter for variables.
Use wx_str() when formatting strings, I think not doing it would lead to a crash, but I've not investigated much.
Translate error message and prefix them.
Fail the comparison if one of the versions fails to parse. I don't know why you've made it differently before
Handle .. I've added a test for it and it failed.
Added temporary tests.
Don't use pointers in loops, generally this is slow if the function is non-inlined, because the compiler cannot optimize away the accesses.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Starting with wxWidgets 3.0 you can use wxString as argument for wxPrintf, from the docs:
// This is the recommended way.wxPrintf("You can do just this: %s",s);wxPrintf("And this (but it is redundant): %s",s.c_str());wxPrintf("And this (not using Unicode): %s",s.mb_str());wxPrintf("And this (always Unicode): %s",s.wc_str());
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you for the contribution. It is a good start but I think it needs a bit more work.
I have 3 complaints about this patch:
This will get you to a single iteration. You can get even fancier/faster if you first check for
attrName[0]=='v'and then get to the slower/fuller checks in an if else fashion.I made the requested changes. As a side effect you can now write more than one test, and the result will be the AND of all.
Calls to CmpVersion() are repeated, but the idea is "don't execute if not needed".
I'm taking this one, too...
@mortenmacfly I've done the initial review, so I can finish it.
@Miguel Gimenez
Currently I don't like this part:
I don't like those c_str() calls and all the casts.
This is from the docs:
Given there is no strtol equivalent in wx I would do the number parsing/conversion manually. Given how much you already have adding a value accumulator and *=10 to it would be fine and probably simpler. I'd probably do it with a separate function like
int extractNumber(int *result, const wxString &s, int searchStart);or just inline in this one. Whatever is less code and looks simpler.I have created a
GetNextValue(const wxString& s, size_t* Index, size_t Length)method and removed xx_str() calls completely.The last patch fails to apply:
F() is not thread safe, because it use some static/shared wxstring if I remember correctly.
I copied the call to DebugLog with F and_T from other part of the code, they are used elsewhere
I don't know how compiler3.patch got so flawed, it even lacks most part of the new code. Here is the last version.
@Miguel Gimenez I've applied your last patch and made some modifications. You can see them here https://github.com/obfuscated/codeblocks_sf/tree/experiments/compiler_version_check I've broke something or you need to do any more changes please post patches against this branch.
What I've changed:
..I've added a test for it and it failed.Starting with wxWidgets 3.0 you can use wxString as argument for wxPrintf, from the docs:
@Miguel Gimenez Do you have any comments on my changes to your patches?
Only the one above about wxPrintf
In svn, thanks. Let me know if I've messed something up.