Rewrite PlainToLatexConverter using QString::replace
Diff Detail
- Repository
- R468 Kile
- Branch
- master
- Lint
No Linters Available - Unit
No Unit Test Coverage - Build Status
Buildable 3599 Build 3617: arc lint + arc unit
Thanks for the patch!
Now, however, there will be 9 iterations (size of m_replaceMap) over 'toConv', whereas previously there was only one.
So, in that sense, I think that the previous code was better.
But the old code can still be improved: 'result.replace' is not really necessary, for example.
The complexity of this function doen't change before it was:
for char in result: # line 50 for replace in replaceMap: # line 53 compare(replace, char)
and now it's
for replace in replaceMap: # line 47 for char in result: # line 48 compare(replace, char)
But I found a better way of doing it, with regex
Don't forget that line 53 is a QMap::find, based on a red-black tree, which implies that not all the comparisons will be carried out.
Also, depending on the iteration order, your second solution could have modified the semantics of the function (~ -> $\\sim$ -> \\$\\sim\\$).
Now, I'm not sure about the regexp solution. It relies on heavy machinery, and it still requires two passes over toConv. Furthermore, some comments would be needed to explain what is being replaced.
I guess we would need some benchmarks to determine which one is faster...
My suggestion would still be to simplify the original code a little bit ;)