Minor performance tweaks

darcs-hash:20051102154159-ac50b-9a32fb6cc654c593048840ebd9f6abb97c2e0bb8.gz
This commit is contained in:
axel 2005-11-03 01:41:59 +10:00
parent c8c3715aac
commit 8d58e58d7b
10 changed files with 53 additions and 49 deletions

View file

@ -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,

View file

@ -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;
}

50
exec.c
View file

@ -113,21 +113,16 @@ int exec_pipe( int fd[2])
}
}
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 );
@ -1051,9 +1047,8 @@ void exec( job_t *j )
}
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
*/

View file

@ -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

View file

@ -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

1
io.c
View file

@ -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 );

1
main.c
View file

@ -212,6 +212,7 @@ int main( int argc, char **argv )
output_init();
event_init();
exec_init();
wutil_init();
parser_init();
builtin_init();
function_init();

View file

@ -500,5 +500,3 @@ void signal_unblock()
sigprocmask(SIG_UNBLOCK, &chldset, 0);
}

10
wutil.c
View file

@ -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();

View file

@ -14,6 +14,12 @@
#include <sys/types.h>
/**
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
*/