From 83c9ce5635ca4c647cd8fc654b63e425c280b2d4 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Wed, 1 Sep 2010 15:10:16 +0200 Subject: [PATCH] Optimization: lower() -> text_lower Version:1.1.48 --- src/command_line.py | 3 ++- src/irpf90.py | 25 +++++++++++++------------ src/irpf90_t.py | 8 ++++++++ src/parsed_text.py | 25 +++++++++++++------------ src/util.py | 4 ++-- src/variable.py | 4 ++-- 6 files changed, 40 insertions(+), 29 deletions(-) diff --git a/src/command_line.py b/src/command_line.py index 5922840..05ece4a 100644 --- a/src/command_line.py +++ b/src/command_line.py @@ -73,7 +73,7 @@ class CommandLine(object): self._touched = [] for o,a in self.opts: if o in [ "-t", options['t'][0] ]: - self._touched.append(a) + self._touched.append(a.lower()) return self._touched touched = property(fget=touched) @@ -142,6 +142,7 @@ do_$LONG = property(fget=do_$LONG) self.do_version or \ self.do_help or \ self.do_preprocess or \ + self.do_touch or \ self.do_init ) return self._do_run do_run = property(fget=do_run) diff --git a/src/irpf90.py b/src/irpf90.py index 96db9b7..6803298 100644 --- a/src/irpf90.py +++ b/src/irpf90.py @@ -48,10 +48,23 @@ def main(): print line.text + if command_line.do_touch: + from variables import variables + for var in command_line.touched: + if var not in variables: + print "%s is not an IRP entity"%(var,) + else: + print "%s touches the following entities:"%(var,) + parents = variables[var].parents + parents.sort() + for x in parents: + print "- %s"%(x,) + if not command_line.do_run: return init() + import irp_stack irp_stack.create() @@ -70,17 +83,5 @@ def main(): import create_man create_man.run() - if command_line.do_touch: - from variables import variables - for var in command_line.touched: - if var not in variables: - print "%s is not an IRP entity"%(var,) - else: - print "%s touches the following entities:"%(var,) - parents = variables[var].parents - parents.sort() - for x in parents: - print "- %s"%(x,) - if __name__ == '__main__': main() diff --git a/src/irpf90_t.py b/src/irpf90_t.py index 8fea5af..ef41966 100644 --- a/src/irpf90_t.py +++ b/src/irpf90_t.py @@ -34,6 +34,14 @@ class Line(object): self.i = i self.text = text self.filename = filename + self._lower = None + + def get_lower(self): + if self._lower is None: + self._lower = self.text.lower() + return self._lower + + text_lower = property(fget=get_lower) class Empty_line(Line): def __init__(self,i,text,filename): diff --git a/src/parsed_text.py b/src/parsed_text.py index 4e04dbb..42cc146 100644 --- a/src/parsed_text.py +++ b/src/parsed_text.py @@ -36,16 +36,17 @@ import error vtuple = map(lambda v: (v, variables[v].same_as, variables[v].regexp), variables.keys()) stuple = map(lambda s: (s, subroutines[s].regexp), subroutines.keys()) stuple = filter(lambda s: subroutines[s[0]].is_function, stuple) +re_string_sub = regexps.re_string.sub def find_variables_in_line(line): assert isinstance(line,Line) result = [] sub_done = False - buffer = line.text.lower() + buffer = line.text_lower for v,same_as,regexp in vtuple: if v in buffer: if not sub_done: - buffer = regexps.re_string.sub('',buffer) + buffer = re_string_sub('',buffer) sub_done = True if regexp.search(buffer) is not None: result.append(same_as) @@ -55,7 +56,7 @@ def find_funcs_in_line(line): assert isinstance(line,Line) result = [] sub_done = False - buffer = line.text.lower() + buffer = line.text_lower for s,regexp in stuple: if s in buffer: if regexp.search(buffer) is not None: @@ -115,7 +116,7 @@ def get_parsed_text(): varlist = [] result.append( ([],line) ) elif isinstance(line,Provide): - l = line.text.lower().split()[1:] + l = line.text_lower.split()[1:] l = filter(lambda x: x not in varlist, l) for v in l: if v not in variables.keys(): @@ -133,10 +134,10 @@ def get_parsed_text(): if subroutines[sub].touches != []: result.append( ([],Provide_all(line.i,"",line.filename)) ) elif isinstance(line,Free): - vars = line.text.split() + vars = line.text_lower.split() if len(vars) < 2: error.fail(line,"Syntax error") - vars = map(lower,vars[1:]) + vars = vars[1:] for v in vars: variables[v].is_freed = True result.append( ([],Simple_line(line.i,"!%s"%(line.text),line.filename)) ) @@ -153,10 +154,10 @@ def get_parsed_text(): variables[line.filename]._is_written = True result.append( ([],Simple_line(line.i,"!%s"%(line.text),line.filename)) ) elif isinstance(line,Touch): - vars = line.text.split() + vars = line.text_lower.split() if len(vars) < 2: error.fail(line,"Syntax error") - vars = map(lower,vars[1:]) + vars = vars[1:] for v in vars: if v not in variables: error.fail(line,"Variable %s unknown"%(v,)) @@ -187,9 +188,9 @@ def get_parsed_text(): elif type(line) in [ Begin_provider, Cont_provider ]: if isinstance(line,Begin_provider): varlist = [] - buffer = map(strip,line.text.replace(']','').split(',')) + buffer = map(strip,line.text_lower.replace(']','').split(',')) assert len(buffer) > 1 - v = buffer[1].lower() + v = buffer[1] varlist.append(v) variable_list = find_variables_in_line(line) try: @@ -373,8 +374,8 @@ def build_needs(): var = None for vars,line in text: if isinstance(line,Begin_provider): - buffer = map(strip,line.text.replace(']',',').split(',')) - var = variables[buffer[1].lower()] + buffer = map(strip,line.text_lower.replace(']',',').split(',')) + var = variables[buffer[1]] var.needs = [] var.to_provide = vars elif isinstance(line,End_provider): diff --git a/src/util.py b/src/util.py index edd51a8..fed2104 100644 --- a/src/util.py +++ b/src/util.py @@ -67,11 +67,11 @@ def build_dim_colons(v): import error def find_subname(line): - buffer = line.text + buffer = line.text_lower if not buffer.endswith(')'): buffer += "()" buffer = buffer.split('(') - buffer = buffer[0].lower().split() + buffer = buffer[0].split() if len(buffer) < 2: error.fail(line,"Syntax Error") return buffer[-1] diff --git a/src/variable.py b/src/variable.py index 5fb6086..e3bbd58 100644 --- a/src/variable.py +++ b/src/variable.py @@ -39,7 +39,7 @@ class Variable(object): assert isinstance(text[0],Begin_provider) self.text = text if name is not None: - self._name = name.lower() + self._name = name ############################################################ def is_touched(self): @@ -543,7 +543,7 @@ class Variable(object): ########################################################## def parents(self): if '_parents' not in self.__dict__: - if not self._is_main: + if not self.is_main: self._parents = [] else: from variables import variables