From 7107e8fd6a93d4f5266475443f82110166d1fc34 Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Fri, 14 May 2010 13:55:25 +0000 Subject: [PATCH] optimization of CPU intensive sanitizeAsciiString --- lib/core/common.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/core/common.py b/lib/core/common.py index 070142ae1..ded0ab668 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -1027,10 +1027,19 @@ def safeStringFormat(formatStr, params): return retVal def sanitizeAsciiString(subject): - retVal = None if subject: - retVal = "".join(char if ord(char) < 128 else '?' for char in subject) - return retVal + index = None + for i in xrange(len(subject)): + if ord(subject[i]) >= 128: + index = i + break + if not index: + return subject + else: + retVal = subject[:index] + "".join(subject[i] if ord(subject[i]) < 128 else '?' for i in xrange(index, len(subject))) + return retVal + else: + return None def decloakToNamedTemporaryFile(filepath, name=None): retVal = NamedTemporaryFile()