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:
Erik Johnson 2018-09-20 21:45:56 -05:00 committed by C. R. Oldham
parent 5ca3b9c424
commit 1593b58e3b
No known key found for this signature in database
GPG Key ID: 336DDBE4E260935A

View File

@ -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