mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 08:58:59 +00:00
Optimize list matcher by doing string membership checks,
This is faster than splitting into a list and then iterating over it.
This commit is contained in:
parent
5ca3b9c424
commit
1593b58e3b
@ -1,17 +1,18 @@
|
|||||||
|
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
'''
|
'''
|
||||||
This is the default list matcher.
|
This is the default list matcher.
|
||||||
'''
|
'''
|
||||||
from __future__ import absolute_import, print_function, unicode_literals
|
from __future__ import absolute_import, print_function, unicode_literals
|
||||||
|
|
||||||
from salt.ext import six # pylint: disable=3rd-party-module-not-gated
|
|
||||||
|
|
||||||
|
|
||||||
def match(tgt):
|
def match(tgt):
|
||||||
'''
|
'''
|
||||||
Determines if this host is on the list
|
Determines if this host is on the list
|
||||||
'''
|
'''
|
||||||
if isinstance(tgt, six.string_types):
|
try:
|
||||||
tgt = tgt.split(',')
|
return __opts__['id'] == tgt \
|
||||||
return bool(__opts__['id'] in tgt)
|
or ',' + __opts__['id'] + ',' in tgt \
|
||||||
|
or tgt.startswith(__opts__['id'] + ',') \
|
||||||
|
or tgt.endswith(',' + __opts__['id'])
|
||||||
|
except (AttributeError, TypeError):
|
||||||
|
return False
|
||||||
|
Loading…
Reference in New Issue
Block a user