aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar axel <axel@liljencrantz.se>2005-11-03 01:41:59 +1000
committerGravatar axel <axel@liljencrantz.se>2005-11-03 01:41:59 +1000
commit8d58e58d7bb53e77752ea2897d100398ac62ace7 (patch)
treec896c3cedbc0bec4230922f442a75473d5007103
parentc8c3715aac2827c9e8b08ad7a5a56b2d88325d14 (diff)
Minor performance tweaks
darcs-hash:20051102154159-ac50b-9a32fb6cc654c593048840ebd9f6abb97c2e0bb8.gz
-rw-r--r--builtin.c3
-rw-r--r--common.c2
-rw-r--r--exec.c62
-rw-r--r--init/fish_function.fish5
-rw-r--r--init/fish_interactive.fish2
-rw-r--r--io.c1
-rw-r--r--main.c9
-rw-r--r--signal.c2
-rw-r--r--wutil.c10
-rw-r--r--wutil.h6
10 files changed, 53 insertions, 49 deletions
diff --git a/builtin.c b/builtin.c
index b587d024..c04d8bb9 100644
--- a/builtin.c
+++ b/builtin.c
@@ -2573,7 +2573,8 @@ static int builtin_end( wchar_t **argv )
parser_get_job_pos()-current_block->tok_pos );
//fwprintf( stderr, L"Function: %ls\n", def );
- if( !parser_test( def, 1 ) )
+
+ if( !is_interactive || !parser_test( def, 1 ) )
{
function_add( current_block->param1.function_name,
def,
diff --git a/common.c b/common.c
index ce7a3588..6feedec0 100644
--- a/common.c
+++ b/common.c
@@ -299,7 +299,7 @@ char *wcs2str( const wchar_t *in )
in,
MAX_UTF8_BYTES*wcslen(in)+1 );
- res = realloc( res, strlen( res )+1 );
+// res = realloc( res, strlen( res )+1 );
return res;
}
diff --git a/exec.c b/exec.c
index 78288da2..a74319bb 100644
--- a/exec.c
+++ b/exec.c
@@ -103,7 +103,7 @@ void exec_close( int fd )
int exec_pipe( int fd[2])
{
int res;
-
+
while( ( res=pipe( fd ) ) )
{
if( errno != EINTR )
@@ -111,23 +111,18 @@ int exec_pipe( int fd[2])
wperror(L"pipe");
return res;
}
- }
+ }
+
+ debug( 4, L"Created pipe using fds %d and %d", fd[0], fd[1]);
if( open_fds == 0 )
{
- open_fds = malloc( sizeof( array_list_t ) );
- if(!open_fds )
- die_mem();
- al_init( open_fds );
+ open_fds = al_new();
}
- if( res != -1 )
- {
- debug( 4, L"Created pipe using fds %d and %d", fd[0], fd[1]);
-
- al_push( open_fds, (void *)(long)fd[0] );
- al_push( open_fds, (void *)(long)fd[1] );
- }
+ al_push( open_fds, (void *)(long)fd[0] );
+ al_push( open_fds, (void *)(long)fd[1] );
+
return res;
}
@@ -183,7 +178,6 @@ static void close_unused_internal_pipes( io_data_t *io )
void exec_init()
{
-
}
void exec_destroy()
@@ -672,7 +666,7 @@ void exec( job_t *j )
pipe_write.io_mode=IO_PIPE;
pipe_read.next=0;
pipe_write.next=0;
- pipe_write.param1.pipe_fd[0]=pipe_write.param1.pipe_fd[1]=0;
+ pipe_write.param1.pipe_fd[0]=pipe_write.param1.pipe_fd[1]=-1;
//fwprintf( stderr, L"Run command %ls\n", j->command );
@@ -696,7 +690,7 @@ void exec( job_t *j )
The loop also has to handle pipelining between the jobs.
*/
- for (p = j->first_process; p; p = p->next)
+ for( p=j->first_process; p; p = p->next )
{
mypipe[1]=-1;
skip_fork=0;
@@ -722,9 +716,11 @@ void exec( job_t *j )
j->io = io_add( j->io, &pipe_read );
}
- if (p->next)
+ if( p->next )
{
- if (exec_pipe( mypipe ) == -1)
+// debug( 1, L"%ls|%ls" , p->argv[0], p->next->argv[0]);
+
+ if( exec_pipe( mypipe ) == -1 )
{
debug( 1, PIPE_ERROR );
wperror (L"pipe");
@@ -775,7 +771,7 @@ void exec( job_t *j )
{
sb_init( &sb );
- for( i=1,arg = p->argv+1; *arg; i++, arg++ )
+ for( i=1, arg=p->argv+1; *arg; i++, arg++ )
{
if( i != 1 )
sb_append( &sb, ARRAY_SEP_STR );
@@ -948,7 +944,7 @@ void exec( job_t *j )
to buffer such io, since otherwisethe internal pipe
buffer might overflow.
*/
- if( !io_buffer)
+ if( !io_buffer )
{
p->completed = 1;
break;
@@ -962,8 +958,8 @@ void exec( job_t *j )
{
- pid = fork ();
- if (pid == 0)
+ pid = fork();
+ if( pid == 0 )
{
/*
This is the child process. Write out the contents of the pipeline.
@@ -975,7 +971,7 @@ void exec( job_t *j )
io_buffer->param2.out_buffer->used );
exit( status );
}
- else if (pid < 0)
+ else if( pid < 0 )
{
/* The fork failed. */
debug( 0, FORK_ERROR );
@@ -1024,7 +1020,7 @@ void exec( job_t *j )
io_data_t *io = io_get( j->io, 1 );
int buffer_stdout = io && io->io_mode == IO_BUFFER;
-
+
if( ( !sb_err->used ) &&
( !p->next ) &&
( sb_out->used ) &&
@@ -1050,10 +1046,9 @@ void exec( job_t *j )
break;
}
-
- pid = fork ();
- if (pid == 0)
+ pid = fork();
+ if( pid == 0 )
{
/*
This is the child process.
@@ -1068,7 +1063,7 @@ void exec( job_t *j )
exit( p->status );
}
- else if (pid < 0)
+ else if( pid < 0 )
{
/* The fork failed. */
debug( 0, FORK_ERROR );
@@ -1098,7 +1093,7 @@ void exec( job_t *j )
// fwprintf( stderr,
// L"fork on %ls\n", j->command );
pid = fork ();
- if (pid == 0)
+ if( pid == 0 )
{
/*
This is the child process.
@@ -1111,7 +1106,7 @@ void exec( job_t *j )
launch_process _never_ returns...
*/
}
- else if (pid < 0)
+ else if( pid < 0 )
{
/* The fork failed. */
debug( 0, FORK_ERROR );
@@ -1138,11 +1133,10 @@ void exec( job_t *j )
}
- if(p->type == INTERNAL_BUILTIN)
+ if( p->type == INTERNAL_BUILTIN )
builtin_pop_io();
-
-
+
/*
Close the pipe the current process uses to read from the previous process_t
*/
@@ -1223,7 +1217,7 @@ int exec_subshell( const wchar_t *cmd,
b_append( io_buffer->param2.out_buffer, &z, 1 );
begin=end=io_buffer->param2.out_buffer->buff;
-
+
if( l )
{
while( 1 )
diff --git a/init/fish_function.fish b/init/fish_function.fish
index e7a86f5e..4ae80d10 100644
--- a/init/fish_function.fish
+++ b/init/fish_function.fish
@@ -32,7 +32,7 @@ function _contains_help -d "Helper function for contains"
end
function contains -d "Test if a key is contained in a set of values"
- while count $argv >/dev/null
+ while set -q argv
switch $argv[1]
case '-h' '--h' '--he' '--hel' '--help'
_contains_help
@@ -56,8 +56,7 @@ function contains -d "Test if a key is contained in a set of values"
set -e argv[1]
end
- if count $argv >/dev/null
- else
+ if not set -q argv
echo "contains: Key not specified"
return 1
end
diff --git a/init/fish_interactive.fish b/init/fish_interactive.fish
index 8a6a7654..ad676a15 100644
--- a/init/fish_interactive.fish
+++ b/init/fish_interactive.fish
@@ -58,7 +58,7 @@ function set_default_color -d "Set an universal variable, unless it has already
set -U -- $argv
return
end
- if contains $$argv[1] (set_color --print-colors)
+ if contains -- $$argv[1] (set_color --print-colors)
return
end
set -U -- $argv
diff --git a/io.c b/io.c
index 498d9b03..41e0892c 100644
--- a/io.c
+++ b/io.c
@@ -95,7 +95,6 @@ io_data_t *io_buffer_create()
b_init( buffer_redirect->param2.out_buffer );
buffer_redirect->fd=1;
-
if( exec_pipe( buffer_redirect->param1.pipe_fd ) == -1 )
{
debug( 1, PIPE_ERROR );
diff --git a/main.c b/main.c
index a2ebb9b5..1e1fbf62 100644
--- a/main.c
+++ b/main.c
@@ -202,25 +202,26 @@ int main( int argc, char **argv )
is_interactive_session &= (cmd == 0);
is_interactive_session &= (my_optind == argc);
is_interactive_session &= isatty(STDIN_FILENO);
-
+
// fwprintf( stderr, L"%d %d %d\n", cmd==0, my_optind == argc, isatty(STDIN_FILENO) );
if( force_interactive )
is_interactive_session=1;
-
+
proc_init();
output_init();
event_init();
exec_init();
+ wutil_init();
parser_init();
builtin_init();
function_init();
env_init();
complete_init();
reader_init();
-
+
reader_push_current_filename( L"(internal)" );
-
+
if( read_init() )
{
if( cmd != 0 )
diff --git a/signal.c b/signal.c
index 115e3837..91876fdb 100644
--- a/signal.c
+++ b/signal.c
@@ -500,5 +500,3 @@ void signal_unblock()
sigprocmask(SIG_UNBLOCK, &chldset, 0);
}
-
-
diff --git a/wutil.c b/wutil.c
index 560ded68..897aef41 100644
--- a/wutil.c
+++ b/wutil.c
@@ -22,6 +22,8 @@
#include "common.h"
#include "wutil.h"
+#define TMP_LEN_MIN 256
+
/**
Buffer for converting wide arguments to narrow arguments, used by
the \c wutil_wcs2str() function.
@@ -37,6 +39,10 @@ static size_t tmp_len=0;
*/
static int wutil_calls = 0;
+void wutil_init()
+{
+}
+
void wutil_destroy()
{
free( tmp );
@@ -57,8 +63,8 @@ static char *wutil_wcs2str( const wchar_t *in )
size_t new_sz =MAX_UTF8_BYTES*wcslen(in)+1;
if( tmp_len < new_sz )
{
- free( tmp );
- tmp = malloc( new_sz );
+ new_sz = maxi( new_sz, TMP_LEN_MIN );
+ tmp = realloc( tmp, new_sz );
if( !tmp )
{
die_mem();
diff --git a/wutil.h b/wutil.h
index 8ce2ac6a..a8e3861d 100644
--- a/wutil.h
+++ b/wutil.h
@@ -15,6 +15,12 @@
/**
+ Call this function on startup to create internal wutil
+ resources. This function doesn't do anything.
+*/
+void wutil_init();
+
+/**
Call this function on exit to free internal wutil resources
*/
void wutil_destroy();