mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-12 21:18:53 +00:00
Minor performance tweaks
darcs-hash:20051102154159-ac50b-9a32fb6cc654c593048840ebd9f6abb97c2e0bb8.gz
This commit is contained in:
parent
c8c3715aac
commit
8d58e58d7b
10 changed files with 53 additions and 49 deletions
|
@ -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,
|
||||
|
|
2
common.c
2
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;
|
||||
}
|
||||
|
|
62
exec.c
62
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 )
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
1
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 );
|
||||
|
|
9
main.c
9
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 )
|
||||
|
|
2
signal.c
2
signal.c
|
@ -500,5 +500,3 @@ void signal_unblock()
|
|||
|
||||
sigprocmask(SIG_UNBLOCK, &chldset, 0);
|
||||
}
|
||||
|
||||
|
||||
|
|
10
wutil.c
10
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();
|
||||
|
|
6
wutil.h
6
wutil.h
|
@ -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
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue