From 972edef34102c4217dfee9f8869e51a15c7a05b0 Mon Sep 17 00:00:00 2001 From: liljencrantz Date: Thu, 2 Aug 2007 08:53:18 +1000 Subject: [PATCH] Replace the contains function with a builtin for performance reasons. The contains function used at lots of forks, which was noticable on systems such as OS X with slow forks, as well as on completions that do a lot of tests, like svn darcs-hash:20070801225318-75c98-48cc4d685ab665c7c2eb93ac3c374bf5afecd28a.gz --- builtin.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 97 insertions(+), 1 deletion(-) diff --git a/builtin.c b/builtin.c index 86e6f27b4..f03cf32d4 100644 --- a/builtin.c +++ b/builtin.c @@ -1893,6 +1893,7 @@ static int builtin_read( wchar_t **argv ) */ static int builtin_status( wchar_t **argv ) { + enum { NORMAL, @@ -1917,6 +1918,7 @@ static int builtin_status( wchar_t **argv ) woptind=0; + const struct woption long_options[] = { @@ -2092,7 +2094,7 @@ static int builtin_status( wchar_t **argv ) case IS_SUBST: return !is_subshell; - + case IS_BLOCK: return !is_block; @@ -2278,6 +2280,96 @@ static int builtin_count( wchar_t ** argv ) return !argc; } +static int builtin_contains( wchar_t ** argv ) +{ + int argc; + argc = builtin_count_args( argv ); + int i; + int res=STATUS_BUILTIN_OK; + wchar_t *needle; + wchar_t **haystack; + + woptind=0; + + const struct woption + long_options[] = + { + { + L"help", no_argument, 0, 'h' + } + , + { + 0, 0, 0, 0 + } + } + ; + + while( 1 ) + { + int opt_index = 0; + + int opt = wgetopt_long( argc, + argv, + L"h", + long_options, + &opt_index ); + if( opt == -1 ) + break; + + switch( opt ) + { + case 0: + if(long_options[opt_index].flag != 0) + break; + sb_printf( sb_err, + BUILTIN_ERR_UNKNOWN, + argv[0], + long_options[opt_index].name ); + builtin_print_help( argv[0], sb_err ); + return STATUS_BUILTIN_ERROR; + + + case 'h': + builtin_print_help( argv[0], sb_out ); + return STATUS_BUILTIN_OK; + + + case ':': + builtin_missing_argument( argv[0], argv[woptind-1] ); + return STATUS_BUILTIN_ERROR; + + case '?': + builtin_unknown_option( argv[0], argv[woptind-1] ); + return STATUS_BUILTIN_ERROR; + + } + + } + + + + needle = argv[woptind]; + if (!needle) + { + sb_printf( sb_err, _( L"%ls: Key not specified\n" ), argv[0] ); + } + + + for( i=woptind+1; i