From abd94e32fb09bb6f02f1abb19e0d8e2e1cb7e186 Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Thu, 7 Aug 2003 09:19:40 +0000 Subject: [PATCH] *Really* optimized objects command. --- plugins/FunCommands.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/plugins/FunCommands.py b/plugins/FunCommands.py index baba4c292..8d6f8db7b 100644 --- a/plugins/FunCommands.py +++ b/plugins/FunCommands.py @@ -480,15 +480,26 @@ class FunCommands(callbacks.Privmsg): """takes no arguments. Returns the number and types of Python objects in memory.""" - def istype(t): - return lambda x: isinstance(x, t) + classes = 0 + functions = 0 + modules = 0 + dicts = 0 + lists = 0 + tuples = 0 objs = gc.get_objects() - classes = ilen(itertools.ifilter(inspect.isclass, objs)) - functions = ilen(itertools.ifilter(inspect.isroutine, objs)) - modules = ilen(itertools.ifilter(inspect.ismodule, objs)) - dicts = ilen(itertools.ifilter(istype(dict), objs)) - lists = ilen(itertools.ifilter(istype(list), objs)) - tuples = ilen(itertools.ifilter(istype(tuple), objs)) + for obj in objs: + if isinstance(obj, tuple): + tuples += 1 + elif inspect.isroutine(obj): + functions += 1 + elif isinstance(obj, dict): + dicts += 1 + elif isinstance(obj, list): + lists += 1 + elif inspect.isclass(obj): + classes += 1 + elif inspect.ismodule(obj): + modules += 1 response = 'I have %s objects: %s modules, %s classes, %s functions, '\ '%s dictionaries, %s lists, and %s tuples (and a few other'\ ' different types).' %\