mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-30 11:21:15 -03:00
Some changes to migrate towards C++ and a multithreaded model
This commit is contained in:
50
intern.cpp
50
intern.cpp
@@ -33,29 +33,29 @@ const wchar_t *intern( const wchar_t *in )
|
||||
const wchar_t *res=0;
|
||||
|
||||
// debug( 0, L"intern %ls", in );
|
||||
|
||||
|
||||
if( !in )
|
||||
return 0;
|
||||
|
||||
|
||||
if( !intern_table )
|
||||
{
|
||||
intern_table = malloc( sizeof( hash_table_t ) );
|
||||
intern_table = (hash_table_t *)malloc( sizeof( hash_table_t ) );
|
||||
if( !intern_table )
|
||||
{
|
||||
DIE_MEM();
|
||||
}
|
||||
hash_init( intern_table, &hash_wcs_func, &hash_wcs_cmp );
|
||||
}
|
||||
|
||||
|
||||
if( intern_static_table )
|
||||
{
|
||||
res = hash_get( intern_static_table, in );
|
||||
res = (const wchar_t *)hash_get( intern_static_table, in );
|
||||
}
|
||||
|
||||
|
||||
if( !res )
|
||||
{
|
||||
res = hash_get( intern_table, in );
|
||||
|
||||
res = (const wchar_t *)hash_get( intern_table, in );
|
||||
|
||||
if( !res )
|
||||
{
|
||||
res = wcsdup( in );
|
||||
@@ -63,39 +63,39 @@ const wchar_t *intern( const wchar_t *in )
|
||||
{
|
||||
DIE_MEM();
|
||||
}
|
||||
|
||||
|
||||
hash_put( intern_table, res, res );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
const wchar_t *intern_static( const wchar_t *in )
|
||||
{
|
||||
const wchar_t *res=0;
|
||||
|
||||
|
||||
if( !in )
|
||||
return 0;
|
||||
|
||||
|
||||
if( !intern_static_table )
|
||||
{
|
||||
intern_static_table = malloc( sizeof( hash_table_t ) );
|
||||
intern_static_table = (hash_table_t *)malloc( sizeof( hash_table_t ) );
|
||||
if( !intern_static_table )
|
||||
{
|
||||
DIE_MEM();
|
||||
DIE_MEM();
|
||||
}
|
||||
hash_init( intern_static_table, &hash_wcs_func, &hash_wcs_cmp );
|
||||
}
|
||||
|
||||
res = hash_get( intern_static_table, in );
|
||||
|
||||
|
||||
res = (const wchar_t *)hash_get( intern_static_table, in );
|
||||
|
||||
if( !res )
|
||||
{
|
||||
res = in;
|
||||
hash_put( intern_static_table, res, res );
|
||||
}
|
||||
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ const wchar_t *intern_static( const wchar_t *in )
|
||||
*/
|
||||
static void clear_value( void *key, void *data )
|
||||
{
|
||||
debug( 3, L"interned string: '%ls'", data );
|
||||
debug( 3, L"interned string: '%ls'", data );
|
||||
free( (void *)data );
|
||||
}
|
||||
|
||||
@@ -112,17 +112,17 @@ void intern_free_all()
|
||||
{
|
||||
if( intern_table )
|
||||
{
|
||||
hash_foreach( intern_table, &clear_value );
|
||||
hash_destroy( intern_table );
|
||||
hash_foreach( intern_table, &clear_value );
|
||||
hash_destroy( intern_table );
|
||||
free( intern_table );
|
||||
intern_table=0;
|
||||
intern_table=0;
|
||||
}
|
||||
|
||||
if( intern_static_table )
|
||||
{
|
||||
hash_destroy( intern_static_table );
|
||||
hash_destroy( intern_static_table );
|
||||
free( intern_static_table );
|
||||
intern_static_table=0;
|
||||
intern_static_table=0;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user