mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 11:09:23 +01:00
Added memoization of hostmaskPatternEqual.
This commit is contained in:
parent
44728222eb
commit
a63d175498
@ -125,10 +125,10 @@ def isChannel(s):
|
||||
_match = fnmatch.fnmatchcase
|
||||
|
||||
_patternCache = {}
|
||||
def hostmaskPatternEqual(pattern, hostmask):
|
||||
def _hostmaskPatternEqual(pattern, hostmask):
|
||||
"""Returns True if hostmask matches the hostmask pattern pattern."""
|
||||
try:
|
||||
return bool(_patternCache[pattern](hostmask))
|
||||
return _patternCache[pattern](hostmask) is not None
|
||||
except KeyError:
|
||||
fd = sio()
|
||||
for c in pattern:
|
||||
@ -149,7 +149,16 @@ def hostmaskPatternEqual(pattern, hostmask):
|
||||
fd.write('$')
|
||||
f = re.compile(fd.getvalue(), re.I).match
|
||||
_patternCache[pattern] = f
|
||||
return bool(f(hostmask))
|
||||
return f(hostmask) is not None
|
||||
|
||||
_hostmaskPatternEqualCache = {}
|
||||
def hostmaskPatternEqual(pattern, hostmask):
|
||||
try:
|
||||
return _hostmaskPatternEqualCache[(pattern, hostmask)]
|
||||
except KeyError:
|
||||
b = _hostmaskPatternEqual(pattern, hostmask)
|
||||
_hostmaskPatternEqualCache[(pattern, hostmask)] = b
|
||||
return b
|
||||
|
||||
_ipchars = string.digits + '.'
|
||||
def isIP(s):
|
||||
|
@ -87,6 +87,8 @@ def upkeep(): # Function to be run on occasion to do upkeep stuff.
|
||||
if not dying:
|
||||
log.debug('Regexp cache size: %s', len(sre._cache))
|
||||
log.debug('Pattern cache size: %s'%len(ircutils._patternCache))
|
||||
log.debug('HostmaskPatternEqual cache size: %s' %
|
||||
len(ircutils._hostmaskPatternEqualCache))
|
||||
log.info('%s upkeep ran.', time.strftime(conf.logTimestampFormat))
|
||||
return collected
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user