10
0
mirror of https://gitlab.com/scemama/irpf90.git synced 2024-12-21 11:53:32 +01:00

Optimization: lower() -> text_lower

Version:1.1.48
This commit is contained in:
Anthony Scemama 2010-09-01 15:10:16 +02:00
parent d3f76c4580
commit 83c9ce5635
6 changed files with 40 additions and 29 deletions

View File

@ -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)

View File

@ -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()

View File

@ -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):

View File

@ -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):

View File

@ -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]

View File

@ -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