Merge. Reworked the added Command.__ne__ operator a bit for a tiny speed optimization (it's after all one of the most called methods in Evennia).

This commit is contained in:
Griatch 2012-11-03 19:21:19 +01:00
commit 8966f03713
9 changed files with 324 additions and 180 deletions

View file

@ -149,8 +149,15 @@ class Command(object):
return cmd in self._matchset
def __ne__(self, cmd):
"The logical negation of __eq__."
return not self.__eq__(cmd)
"""
The logical negation of __eq__. Since this is one of the
most called methods in Evennia (along with __eq__) we do some
code-duplication here rather than issuing a method-lookup to __eq__.
"""
try:
return not cmd.key in self._matcheset
except AttributeError:
return not cmd in self._matchset
def __contains__(self, query):
"""

View file

@ -212,7 +212,7 @@ class CmdBan(MuxCommand):
# replace * with regex form and compile it
ipregex = ban.replace('.','\.')
ipregex = ipregex.replace('*', '[0-9]{1,3}')
print "regex:",ipregex
#print "regex:",ipregex
ipregex = re.compile(r"%s" % ipregex)
bantup = ("", ban, ipregex, now, reason)
# save updated banlist

View file

@ -281,7 +281,7 @@ class CmdGet(MuxCommand):
if caller == obj:
caller.msg("You can't get yourself.")
return
print obj, obj.location, caller, caller==obj.location
#print obj, obj.location, caller, caller==obj.location
if caller == obj.location:
caller.msg("You already hold that.")
return

View file

@ -11,6 +11,7 @@ import sys
import django, twisted
from django.conf import settings
from src.server.caches import get_cache_sizes
from src.server.sessionhandler import SESSIONS
from src.scripts.models import ScriptDB
from src.objects.models import ObjectDB
@ -607,13 +608,11 @@ class CmdServerLoad(MuxCommand):
if not utils.host_os_is('posix'):
string = "Process listings are only available under Linux/Unix."
else:
global _resource, _idmapper, _attribute_cache
global _resource, _idmapper
if not _resource:
import resource as _resource
if not _idmapper:
from src.utils.idmapper import base as _idmapper
if not _attribute_cache:
from src.typeclasses.models import _ATTRIBUTE_CACHE as _attribute_cache
import resource
loadavg = os.getloadavg()
@ -684,10 +683,13 @@ class CmdServerLoad(MuxCommand):
ftable = utils.format_table(table, 5)
for row in ftable:
string += "\n " + row[0] + row[1] + row[2]
# attribute cache
size = sum([sum([getsizeof(obj) for obj in dic.values()]) for dic in _attribute_cache.values()])/1024.0
count = sum([len(dic) for dic in _attribute_cache.values()])
string += "\n{w On-entity Attribute cache usage:{n %5.2f MB (%i items)" % (size, count)
# get sizes of other caches
attr_cache_info, field_cache_info, prop_cache_info = get_cache_sizes()
#size = sum([sum([getsizeof(obj) for obj in dic.values()]) for dic in _attribute_cache.values()])/1024.0
#count = sum([len(dic) for dic in _attribute_cache.values()])
string += "\n{w On-entity Attribute cache usage:{n %5.2f MB (%i attrs)" % (attr_cache_info[1], attr_cache_info[0])
string += "\n{w On-entity Field cache usage:{n %5.2f MB (%i fields)" % (field_cache_info[1], field_cache_info[0])
string += "\n{w On-entity Property cache usage:{n %5.2f MB (%i props)" % (prop_cache_info[1], prop_cache_info[0])
caller.msg(string)