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