From edc6df44de4e0f22322062c7c7e1b973bd89f4cd Mon Sep 17 00:00:00 2001
From: Jan Chren <dev.rindeal@gmail.com>
Date: Fri, 22 Apr 2016 14:21:08 +0200
Subject: [PATCH] isolated-functions.sh: eliminate loop in has()

Looping is slow and clutters debug log.
Still this wouldn't matter that much if has() wasn't one of the most used
functions.

Thus this patch should bring a general improvement.
---
 bin/isolated-functions.sh | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/bin/isolated-functions.sh b/bin/isolated-functions.sh
index e320f71..6900f99 100644
--- a/bin/isolated-functions.sh
+++ b/bin/isolated-functions.sh
@@ -463,14 +463,12 @@ hasv() {
 }

 has() {
-       local needle=$1
+       local needle=$'\a'"$1"$'\a'
        shift
+       local IFS=$'\a'
+       local haystack=$'\a'"$@"$'\a'

-       local x
-       for x in "$@"; do
-               [ "${x}" = "${needle}" ] && return 0
-       done
-       return 1
+       [[ "${haystack}" == *"${needle}"* ]]
 }

 __repo_attr() {
--
2.7.3