mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-25 20:33:08 +00:00
Use the intern function to share the strings used to describe various key bindings. This saves both performance, code size and memory use, but there is a pathological case where the user continually changes key bindings, resulting in more allocated memory than needed.
darcs-hash:20060621140344-ac50b-c7eb89a94a96538215f9a6737f8e4bacd6a801fb.gz
This commit is contained in:
parent
407c96e943
commit
2076944268
5 changed files with 17 additions and 26 deletions
34
input.c
34
input.c
|
@ -61,6 +61,7 @@ implementation in fish is as of yet incomplete.
|
|||
#include "signal.h"
|
||||
#include "translate.h"
|
||||
#include "output.h"
|
||||
#include "intern.h"
|
||||
|
||||
static void input_read_inputrc( wchar_t *fn );
|
||||
|
||||
|
@ -71,9 +72,9 @@ static void input_read_inputrc( wchar_t *fn );
|
|||
|
||||
typedef struct
|
||||
{
|
||||
wchar_t *seq; /**< Character sequence which generates this event */
|
||||
wchar_t *seq_desc; /**< Description of the character sequence suitable for printing on-screen */
|
||||
wchar_t *command; /**< command that should be evaluated by this mapping */
|
||||
const wchar_t *seq; /**< Character sequence which generates this event */
|
||||
const wchar_t *seq_desc; /**< Description of the character sequence suitable for printing on-screen */
|
||||
const wchar_t *command; /**< command that should be evaluated by this mapping */
|
||||
|
||||
}
|
||||
mapping;
|
||||
|
@ -237,7 +238,7 @@ static int inputrc_error = 0;
|
|||
*/
|
||||
static int is_init = 0;
|
||||
|
||||
wchar_t input_get_code( wchar_t *name )
|
||||
wchar_t input_get_code( const wchar_t *name )
|
||||
{
|
||||
|
||||
int i;
|
||||
|
@ -340,18 +341,16 @@ void add_mapping( const wchar_t *mode,
|
|||
mapping *m = (mapping *)al_get( mappings, i );
|
||||
if( wcscmp( m->seq, s ) == 0 )
|
||||
{
|
||||
free( m->command );
|
||||
free( m->seq_desc );
|
||||
m->seq_desc = wcsdup(d );
|
||||
m->command=wcsdup(c);
|
||||
m->seq_desc = intern(d);
|
||||
m->command = intern(c);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
mapping *m = malloc( sizeof( mapping ) );
|
||||
m->seq = wcsdup( s );
|
||||
m->seq_desc = wcsdup(d );
|
||||
m->command=wcsdup(c);
|
||||
m->seq = intern( s );
|
||||
m->seq_desc = intern(d );
|
||||
m->command = intern(c);
|
||||
al_push( mappings, m );
|
||||
}
|
||||
|
||||
|
@ -1427,20 +1426,11 @@ int input_init()
|
|||
*/
|
||||
static void destroy_mapping( void *key, void *val )
|
||||
{
|
||||
int i;
|
||||
array_list_t *mappings = (array_list_t *)val;
|
||||
|
||||
for( i=0; i<al_get_count( mappings ); i++ )
|
||||
{
|
||||
mapping *m = (mapping *)al_get( mappings, i );
|
||||
free( m->seq );
|
||||
free( m->seq_desc );
|
||||
|
||||
free( m->command );
|
||||
free(m );
|
||||
}
|
||||
|
||||
al_foreach( mappings, &free );
|
||||
al_destroy( mappings );
|
||||
|
||||
free((void *)key);
|
||||
free((void *)val);
|
||||
}
|
||||
|
|
2
input.h
2
input.h
|
@ -111,6 +111,6 @@ void input_parse_inputrc_line( wchar_t *cmd );
|
|||
/**
|
||||
Returns the function for the given function name.
|
||||
*/
|
||||
wchar_t input_get_code( wchar_t *name );
|
||||
wchar_t input_get_code( const wchar_t *name );
|
||||
|
||||
#endif
|
||||
|
|
3
main.c
3
main.c
|
@ -117,6 +117,8 @@ int main( int argc, char **argv )
|
|||
|
||||
char *cmd=0;
|
||||
|
||||
halloc_util_init();
|
||||
|
||||
wsetlocale( LC_ALL, L"" );
|
||||
is_interactive_session=1;
|
||||
program_name=L"fish";
|
||||
|
@ -258,7 +260,6 @@ int main( int argc, char **argv )
|
|||
no_exec = 0;
|
||||
}
|
||||
|
||||
halloc_util_init();
|
||||
|
||||
proc_init();
|
||||
event_init();
|
||||
|
|
2
reader.c
2
reader.c
|
@ -2080,7 +2080,7 @@ int reader_get_cursor_pos()
|
|||
}
|
||||
|
||||
|
||||
void reader_run_command( wchar_t *cmd )
|
||||
void reader_run_command( const wchar_t *cmd )
|
||||
{
|
||||
|
||||
wchar_t *ft;
|
||||
|
|
2
reader.h
2
reader.h
|
@ -72,7 +72,7 @@ void repaint();
|
|||
Run the specified command with the correct terminal modes, and
|
||||
while taking care to perform job notification, set the title, etc.
|
||||
*/
|
||||
void reader_run_command( wchar_t *buff );
|
||||
void reader_run_command( const wchar_t *buff );
|
||||
|
||||
/**
|
||||
Get the string of character currently entered into the command
|
||||
|
|
Loading…
Reference in a new issue