This patch adds the following verbs to the XML parser:
version_greater
version_greater_equal
version_equal
version_not_equal
version_less_equal
version_less
comparing strings in the form major[.minor[.patch[.tweak]]]
but not limited to four parts.
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:
1. 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 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:
1. 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.
2. Use wx_str() when formatting strings, I think not doing it would lead to a crash, but I've not investigated much.
3. Translate error message and prefix them.
4. Fail the comparison if one of the versions fails to parse. I don't know why you've made it differently before
5. Handle
..
I've added a test for it and it failed.6. Added temporary tests.
7. Don't use pointers in loops, generally this is slow if the function is non-inlined, because the compiler cannot optimize away the accesses.
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.