Hi, On Thu, 1 Nov 2018 at 18:43, Richard Kimberly Heck <rikih...@lyx.org> wrote:
> > My second suggestion in the last email is along these lines, too. I > should have added that it is only when the language is Hebrew that we do > any of the other tests. (We have to go through the whole file, of > course, to find out whether Hebrew is ever used.) > > I've followed the suggestion and now it runs much faster. See my attached patch. Thanks, Guy
From d6fe68cfbbb3e9cbd0fd9748ebb9b392dfc4bb96 Mon Sep 17 00:00:00 2001 From: Guy Rutenberg <guyrutenb...@gmail.com> Date: Thu, 1 Nov 2018 19:23:17 +0200 Subject: [PATCH] Fix performance when fixing parentheses in Hebrew. --- lib/lyx2lyx/lyx2lyx_tools.py | 15 --------------- lib/lyx2lyx/lyx_2_4.py | 10 ++++++---- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/lib/lyx2lyx/lyx2lyx_tools.py b/lib/lyx2lyx/lyx2lyx_tools.py index 51412e5b31..73f7d78c10 100644 --- a/lib/lyx2lyx/lyx2lyx_tools.py +++ b/lib/lyx2lyx/lyx2lyx_tools.py @@ -83,9 +83,6 @@ insert_document_option(document, option): remove_document_option(document, option): Remove _option_ as a document option. - -get_language_for_line(document, i): - Return the language setting for line number i. ''' import re @@ -607,15 +604,3 @@ def is_document_option(document, option): return False return True - - -def get_language_for_line(document, i): - " Return the language for line number i" - layout = get_containing_layout(document.body, i) - if not layout: - return document.language - start_of_par = layout[3] - for line in document.body[i:start_of_par:-1]: - if line.startswith('\\lang '): - return line[len('\\lang '):] - return document.language diff --git a/lib/lyx2lyx/lyx_2_4.py b/lib/lyx2lyx/lyx_2_4.py index b6b626c316..670e31abfc 100644 --- a/lib/lyx2lyx/lyx_2_4.py +++ b/lib/lyx2lyx/lyx_2_4.py @@ -1383,11 +1383,13 @@ def revert_lformatinfo(document): def convert_hebrew_parentheses(document): " Don't reverse parentheses in Hebrew text" + current_language = document.language for i, line in enumerate(document.body): - if line.startswith('\\\\'): - # not a text line, skip - continue - if get_language_for_line(document, i) == 'hebrew': + if line.startswith('\\lang '): + current_language = line[len('\\lang '):] + elif line.startswith('\\end_layout'): + current_language = document.language + if current_language == 'hebrew' and not line.startswith('\\'): document.body[i] = line.replace('(','\x00').replace(')','(').replace('\x00',')') -- 2.11.0