optimization of “_morph” function

Bug #717964 reported by --deleted--
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Lightproof
Fix Committed
Undecided
Unassigned

Bug Description

At the moment, the result of the command “analyze” is stored as a string for each words in a global array, and we split it each times we need to know the morphologies of a word. Instead of doing it repeatedly, we can do it once for each word.

def _morph(rLoc, word, pattern, onlyaffix):
    global analyses
    if word == None:
        return None
    if word not in analyses:
        x = spellchecker.spell(u"<?xml?><query type='analyze'><word>" + word + "</word></query>", rLoc, ())
        if not x:
            return None
        t = x.getAlternatives()
        if not t:
            t = [""]
        analyses[word] = t[0]
    a = analyses[word].split("</a>")[:-1] <----- here is the job done too many times
    [...]

New function :

def _morph(rLoc, word, pattern, onlyaffix):
    global analyses
    if word == None:
        return None
    if word not in analyses:
        x = spellchecker.spell(u"<?xml?><query type='analyze'><word>" + word + "</word></query>", rLoc, ())
        if not x:
            return None
        t = x.getAlternatives()
        if not t:
            t = [""]
        analyses[word] = t[0].split("</a>")[:-1] <----- here is the job done once for each word
    a = analyses[word]
    [...]

Changed in lightproof:
status: New → Fix Committed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.