Rewrite PlainToLatexConverter
AbandonedPublic

Authored by ognarb on Oct 2 2018, 2:04 PM.

Details

Reviewers
mludwig
Group Reviewers
Kile
Summary

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
ognarb created this revision.Oct 2 2018, 2:04 PM
Restricted Application added a project: Kile. · View Herald TranscriptOct 2 2018, 2:04 PM
Restricted Application added a subscriber: Kile. · View Herald Transcript
ognarb requested review of this revision.Oct 2 2018, 2:04 PM
ognarb added a reviewer: Kile.Oct 2 2018, 2:04 PM
ognarb updated this revision to Diff 42722.Oct 2 2018, 2:05 PM

Remove a useless header

mludwig requested changes to this revision.Oct 7 2018, 4:27 PM

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.

This revision now requires changes to proceed.Oct 7 2018, 4:27 PM
ognarb added a comment.EditedOct 7 2018, 4:39 PM

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

ognarb updated this revision to Diff 43064.Oct 7 2018, 5:11 PM

Using regex

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 ;)

ognarb abandoned this revision.Jan 6 2019, 2:12 PM