1 |
From edc6df44de4e0f22322062c7c7e1b973bd89f4cd Mon Sep 17 00:00:00 2001 |
2 |
From: Jan Chren <dev.rindeal@×××××.com> |
3 |
Date: Fri, 22 Apr 2016 14:21:08 +0200 |
4 |
Subject: [PATCH] isolated-functions.sh: eliminate loop in has() |
5 |
|
6 |
Looping is slow and clutters debug log. |
7 |
Still this wouldn't matter that much if has() wasn't one of the most used |
8 |
functions. |
9 |
|
10 |
Thus this patch should bring a general improvement. |
11 |
--- |
12 |
bin/isolated-functions.sh | 10 ++++------ |
13 |
1 file changed, 4 insertions(+), 6 deletions(-) |
14 |
|
15 |
diff --git a/bin/isolated-functions.sh b/bin/isolated-functions.sh |
16 |
index e320f71..6900f99 100644 |
17 |
--- a/bin/isolated-functions.sh |
18 |
+++ b/bin/isolated-functions.sh |
19 |
@@ -463,14 +463,12 @@ hasv() { |
20 |
} |
21 |
|
22 |
has() { |
23 |
- local needle=$1 |
24 |
+ local needle=$'\a'"$1"$'\a' |
25 |
shift |
26 |
+ local IFS=$'\a' |
27 |
+ local haystack=$'\a'"$@"$'\a' |
28 |
|
29 |
- local x |
30 |
- for x in "$@"; do |
31 |
- [ "${x}" = "${needle}" ] && return 0 |
32 |
- done |
33 |
- return 1 |
34 |
+ [[ "${haystack}" == *"${needle}"* ]] |
35 |
} |
36 |
|
37 |
__repo_attr() { |
38 |
-- |
39 |
2.7.3 |