Commit c3e6b0d4 authored by Michal Čihař's avatar Michal Čihař

Cache BBcode and printf parsing results for source string

parent e2438f2e
...@@ -219,7 +219,11 @@ class Check(object): ...@@ -219,7 +219,11 @@ class Check(object):
''' '''
if len(target) == 0 or len(source) == 0: if len(target) == 0 or len(source) == 0:
return False return False
src_matches = set([x[0] for x in regex.findall(source)]) # Try geting source parsing from cache
src_matches = self.get_cache(unit)
# Cache miss
if src_matches is None:
src_matches = set([x[0] for x in regex.findall(source)])
tgt_matches = set([x[0] for x in regex.findall(target)]) tgt_matches = set([x[0] for x in regex.findall(target)])
# We ignore %% as this is really not relevant. However it needs # We ignore %% as this is really not relevant. However it needs
# to be matched to prevent handling %%s as %s. # to be matched to prevent handling %%s as %s.
...@@ -615,14 +619,22 @@ class BBCodeCheck(TargetCheck): ...@@ -615,14 +619,22 @@ class BBCodeCheck(TargetCheck):
description = _('BBcode in translation does not match source') description = _('BBcode in translation does not match source')
def check_single(self, source, target, flags, language, unit): def check_single(self, source, target, flags, language, unit):
src_match = BBCODE_MATCH.findall(source) # Try geting source parsing from cache
src_match = self.get_cache(unit)
# Cache miss
if src_match is None:
src_match = BBCODE_MATCH.findall(source)
# Any BBCode in source?
if len(src_match) == 0: if len(src_match) == 0:
return False return False
# Parse target
tgt_match = BBCODE_MATCH.findall(target) tgt_match = BBCODE_MATCH.findall(target)
if len(src_match) != len(tgt_match): if len(src_match) != len(tgt_match):
return True return True
src_tags = set([x[0] for x in src_match]) src_tags = set([x[0] for x in src_match])
tgt_tags = set([x[0] for x in tgt_match]) tgt_tags = set([x[0] for x in tgt_match])
return (src_tags != tgt_tags) return (src_tags != tgt_tags)
class ZeroWidthSpaceCheck(TargetCheck): class ZeroWidthSpaceCheck(TargetCheck):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment