diff --git a/src/engine/lists.cpp b/src/engine/lists.cpp index 590c6bfe8..55acb3f21 100644 --- a/src/engine/lists.cpp +++ b/src/engine/lists.cpp @@ -14,47 +14,15 @@ #include -static const size_t freelist_size = 16; - -static LIST * freelist[ freelist_size ]; /* junkpile for list_dealloc() */ - -static int32_t get_bucket_size( size_t bucket ) -{ - return int32_t(1) << ( bucket < freelist_size ? bucket : ( freelist_size - 1 ) ); -} - -static size_t get_bucket( int32_t size ) -{ - size_t bucket = 0; - while ( ( bucket < freelist_size ) && ( size > get_bucket_size( bucket ) ) ) ++bucket; - return bucket; -} - static LIST * list_alloc( int32_t size ) { - size_t bucket = get_bucket( size ); - if ( freelist[ bucket ] ) - { - LIST * result = freelist[ bucket ]; - freelist[ bucket ] = result->impl.next; - return result; - } - return (LIST *)BJAM_MALLOC( sizeof( LIST ) + get_bucket_size( bucket ) * - sizeof( OBJECT * ) ); + if ( size == 0 ) return L0; + return (LIST *)BJAM_MALLOC( sizeof( LIST ) + size * sizeof( OBJECT * ) ); } static void list_dealloc( LIST * l ) { - int32_t size = list_length( l ); - size_t bucket; - LIST * node = l; - - if ( size == 0 ) return; - - bucket = get_bucket( size );; - - node->impl.next = freelist[ bucket ]; - freelist[ bucket ] = node; + // if ( l ) BJAM_FREE( l ); } /* @@ -70,18 +38,11 @@ LIST * list_append( LIST * l, LIST * nl ) int32_t l_size = list_length( l ); int32_t nl_size = list_length( nl ); int32_t size = l_size + nl_size; - size_t bucket = get_bucket( size ); - - /* Do we need to reallocate? */ - if ( l_size <= get_bucket_size( bucket ) ) - { - LIST * result = list_alloc( size ); - memcpy( list_begin( result ), list_begin( l ), l_size * sizeof( - OBJECT * ) ); - list_dealloc( l ); - l = result; - } - + LIST * result = list_alloc( size ); + memcpy( list_begin( result ), list_begin( l ), l_size * sizeof( + OBJECT * ) ); + list_dealloc( l ); + l = result; l->impl.size = size; memcpy( list_begin( l ) + l_size, list_begin( nl ), nl_size * sizeof( OBJECT * ) ); @@ -124,7 +85,7 @@ LIST * list_push_back( LIST * head, OBJECT * value ) { head = list_alloc( 1 ); } - else if ( ( ( size - 1 ) & size ) == 0 ) + else { LIST * l = list_alloc( size + 1 ); memcpy( l, head, sizeof( LIST ) + size * sizeof( OBJECT * ) ); @@ -368,16 +329,6 @@ LIST * list_unique( LIST * sorted_list ) void list_done() { - for ( int32_t i = 0; i < int32_t(sizeof( freelist ) / sizeof( freelist[ 0 ] )); ++i ) - { - LIST * l = freelist[ i ]; - while ( l ) - { - LIST * const tmp = l; - l = l->impl.next; - BJAM_FREE( tmp ); - } - } }