1 |
On 4/22/16 9:07 AM, rindeal wrote: |
2 |
>>From edc6df44de4e0f22322062c7c7e1b973bd89f4cd Mon Sep 17 00:00:00 2001 |
3 |
> From: Jan Chren <dev.rindeal@×××××.com> |
4 |
> Date: Fri, 22 Apr 2016 14:21:08 +0200 |
5 |
> Subject: [PATCH] isolated-functions.sh: eliminate loop in has() |
6 |
> |
7 |
> Looping is slow and clutters debug log. |
8 |
> Still this wouldn't matter that much if has() wasn't one of the most used |
9 |
> functions. |
10 |
|
11 |
do you have any benchmarks? what you say makes sense but i'm not sure |
12 |
of the implementation details of "$A" == "*${B}*" so its hard to say. |
13 |
|
14 |
> |
15 |
> Thus this patch should bring a general improvement. |
16 |
> --- |
17 |
> bin/isolated-functions.sh | 10 ++++------ |
18 |
> 1 file changed, 4 insertions(+), 6 deletions(-) |
19 |
> |
20 |
> diff --git a/bin/isolated-functions.sh b/bin/isolated-functions.sh |
21 |
> index e320f71..6900f99 100644 |
22 |
> --- a/bin/isolated-functions.sh |
23 |
> +++ b/bin/isolated-functions.sh |
24 |
> @@ -463,14 +463,12 @@ hasv() { |
25 |
> } |
26 |
> |
27 |
> has() { |
28 |
> - local needle=$1 |
29 |
> + local needle=$'\a'"$1"$'\a' |
30 |
|
31 |
why the ascii bell? just because you'd never expect it in a parameter |
32 |
to has? |
33 |
|
34 |
> shift |
35 |
> + local IFS=$'\a' |
36 |
> + local haystack=$'\a'"$@"$'\a' |
37 |
|
38 |
you want "$*" here not "$@" |
39 |
|
40 |
> |
41 |
> - local x |
42 |
> - for x in "$@"; do |
43 |
> - [ "${x}" = "${needle}" ] && return 0 |
44 |
> - done |
45 |
> - return 1 |
46 |
> + [[ "${haystack}" == *"${needle}"* ]] |
47 |
> } |
48 |
> |
49 |
> __repo_attr() { |
50 |
> -- |
51 |
> 2.7.3 |
52 |
> |
53 |
|
54 |
|
55 |
-- |
56 |
Anthony G. Basile, Ph. D. |
57 |
Chair of Information Technology |
58 |
D'Youville College |
59 |
Buffalo, NY 14201 |
60 |
(716) 829-8197 |