From: <lu...@us...> - 2010-05-15 12:53:48
|
Revision: 411 http://pyscard.svn.sourceforge.net/pyscard/?rev=411&view=rev Author: ludov Date: 2010-05-15 12:53:38 +0000 (Sat, 15 May 2010) Log Message: ----------- Use the RE engine only when needed. Speed gain: x5 Modified Paths: -------------- trunk/contrib/parseATR/parseATR.py Modified: trunk/contrib/parseATR/parseATR.py =================================================================== --- trunk/contrib/parseATR/parseATR.py 2010-05-15 12:15:08 UTC (rev 410) +++ trunk/contrib/parseATR/parseATR.py 2010-05-15 12:53:38 UTC (rev 411) @@ -735,13 +735,23 @@ card = [] atr = toHexString(normalize(atr)) file = open(atr_file) + + # find a . * or [ in the ATR to know if we must use a RE or not + re_match = re.compile("[\\.\\*\\[]") + for line in file: if line.startswith("#") or line.startswith("\t") or line == "\n": continue line = line.rstrip("\n") - pattern = re.compile(line) - if pattern.match(atr): + # does the ATR in the file uses a RE? + if re_match.search(line): + # use the RE engine (slow) + found = re.match(line, atr) + else: + # use string compare (fast) + found = line == atr + if found: # found the ATR if atr != line: card.append("") This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |