Menu

editor.rereplace(regex, replace) extremely slow

Ron Jensen
2014-02-12
2014-02-13
  • Ron Jensen

    Ron Jensen - 2014-02-12

    I've replaced some recorded macros with python scripts that mostly call

    editor.rereplace(regex, replace)

    Compared to the macro engine the python version is extremely slow. The macro finishes almost instantly, the regex version runs for nearly a minute. It looks to me like updates are disabled while the macro is running, but not when the python reregex runs. That is, I can watch the replacements happen one-by-one and see the length count change while the script is running.

    Is there some way to speed the rereplace() function up? Possibly by disabling screen refresh during the call?

    I don't want to use pyreplace as the regex language in Python seems not as compete as the one in Scintilla (boost).

    Thanks,
    Ron

     
  • Dave Brotherstone

    This is being worked on as we speak. I've got most things working, there's just a few little things still to implement (passing flags, defining start and stop points and a maximum count of replaces to perform).

    The new routine replaces all of pyreplace, pymlreplace and rereplace, with a single rereplace function that can do all of the above. I've got today and tomorrow to finish it off, so hopefully, hopefully, by the weekend, I should at least have a test version ready.

    On a long replace, it's an order of magnitude faster (a really bad pyreplace took 50 seconds on my PC, with the new method it took just under 2).

    The new routine uses the same boost regex engine that Scintilla uses, but can also be used with a python function as the replacement, and you get an object that looks more-or-less like a python re.Match object.

    There should be an announcement on the Plugin Development forum and here http://sourceforge.net/p/npppythonscript/discussion/1188885/ as soon as it's ready for testing - it'd be great if you could test your script with the new version.

    Thanks,
    Dave.

     
  • Ron Jensen

    Ron Jensen - 2014-02-13

    Thanks Dave,

    I'll be happy to test it on when its ready. I'm currently running version 0.9.2.0 and NPP 6.4.5

    Ron