Move special handling of DISPLAY environment variable from etc/config.fish to fish itself to reduce number of fork calls made at launch

This commit is contained in:
ridiculousfish 2012-03-06 15:51:48 -08:00
parent 36fe1e4a46
commit 68b93c624f
5 changed files with 29 additions and 25 deletions

32
env.cpp
View File

@ -94,6 +94,9 @@ struct var_entry_t
typedef std::map<wcstring, var_entry_t*> var_table_t;
bool g_log_forks = true;
/**
Struct representing one level in the function variable stack
*/
@ -498,6 +501,15 @@ static void env_set_defaults()
}
// Some variables should not be arrays. This used to be handled by a startup script, but we'd like to get down to 0 forks for startup, so handle it here.
static bool variable_can_be_array(const wchar_t *key) {
if (! wcscmp(key, L"DISPLAY")) {
return false;
} else {
return true;
}
}
void env_init()
{
char **p;
@ -555,7 +567,6 @@ void env_init()
for( p=environ?environ:__environ; p && *p; p++ )
{
wchar_t *key, *val;
wchar_t *pos;
key = str2wcs(*p);
@ -574,16 +585,15 @@ void env_init()
{
*val = L'\0';
val++;
pos=val;
//fwprintf( stderr, L"Set $%ls to %ls\n", key, val );
while( *pos )
{
if( *pos == L':' )
{
*pos = ARRAY_SEP;
}
pos++;
}
//fwprintf( stderr, L"Set $%ls to %ls\n", key, val );
if (variable_can_be_array(val)) {
for (size_t i=0; val[i] != L'\0'; i++) {
if( val[i] == L':' ) {
val[i] = ARRAY_SEP;
}
}
}
env_set( key, val, ENV_EXPORT | ENV_GLOBAL );
}

2
env.h
View File

@ -183,5 +183,7 @@ public:
static const wchar_t * const highlighting_keys[];
};
extern bool g_log_forks;
#endif

View File

@ -38,17 +38,6 @@ if status --is-login
end
end
#
# There are variables that contain colons that are not arrays. This
# reverts them back to regular strings.
#
for i in DISPLAY
if set -q $i
set -- $i (printf ":%s" $$i|cut -c 2-)
end
end
#
# Load additional initialization files
#

View File

@ -1238,7 +1238,8 @@ void exec( parser_t &parser, job_t *j )
const char *actual_cmd = actual_cmd_str.c_str();
const wchar_t *reader_current_filename();
printf("forking for '%s' in '%ls'\n", actual_cmd, reader_current_filename());
if (g_log_forks)
printf("forking for '%s' in '%ls'\n", actual_cmd, reader_current_filename());
pid = execute_fork(true /* must drain threads */);
if( pid == 0 )
{

View File

@ -305,7 +305,8 @@ int main( int argc, char **argv )
parser_t &parser = parser_t::principal_parser();
printf("%d: g_fork_count: %d\n", __LINE__, g_fork_count);
if (g_log_forks)
printf("%d: g_fork_count: %d\n", __LINE__, g_fork_count);
if( read_init() )
{
@ -390,7 +391,8 @@ int main( int argc, char **argv )
env_destroy();
printf("%d: g_fork_count: %d\n", __LINE__, g_fork_count);
if (g_log_forks)
printf("%d: g_fork_count: %d\n", __LINE__, g_fork_count);
return res?STATUS_UNKNOWN_COMMAND:proc_get_last_status();
}