From 156935eece37d0e52e887295a70154819722c5c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ozan=20=C3=87a=C4=9Flayan?= Date: Thu, 9 Jun 2011 11:36:56 +0000 Subject: [PATCH] graph: Use list comprehension for value sanitizing which is ~2x faster --- pisi/graph.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/pisi/graph.py b/pisi/graph.py index 7d6462f6..28e5a27a 100644 --- a/pisi/graph.py +++ b/pisi/graph.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # -# Copyright (C) 2005 - 2007, TUBITAK/UEKAE +# Copyright (C) 2005 - 2011, TUBITAK/UEKAE # # This program is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free @@ -12,16 +12,12 @@ # the most simple minded digraph class ever -import string - import pisi import gettext __trans = gettext.translation('pisi', fallback=True) _ = __trans.ugettext -# not an error! - class CycleException(pisi.Exception): def __init__(self, cycle): self.cycle = cycle @@ -141,12 +137,10 @@ class Digraph(object): return list def id_str(self, u): - def repl(char): - if char in string.punctuation: - return '_' - else: - return char - return pisi.util.flatten_list(map(repl, str(u))) + # Graph format only accepts underscores as key values + # Sanitize the values. This is 2x faster than the old method. + return ''.join([ch if ch not in '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~' \ + else '_' for ch in u]) def write_graphviz(self, f): f.write('digraph G {\n')