| 109 | */ |
| 110 | |
| 111 | LIST * list_push_back( LIST * head, OBJECT * value ) |
| 112 | { |
| 113 | unsigned int size = list_length( head ); |
| 114 | unsigned int i; |
| 115 | |
| 116 | if ( DEBUG_LISTS ) |
| 117 | printf( "list > %s <\n", object_str( value ) ); |
| 118 | |
| 119 | /* If the size is a power of 2, reallocate. */ |
| 120 | if ( size == 0 ) |
| 121 | { |
| 122 | head = list_alloc( 1 ); |
| 123 | } |
| 124 | else if ( ( ( size - 1 ) & size ) == 0 ) |
| 125 | { |
| 126 | LIST * l = list_alloc( size + 1 ); |
| 127 | memcpy( l, head, sizeof( LIST ) + size * sizeof( OBJECT * ) ); |
| 128 | list_dealloc( head ); |
| 129 | head = l; |
| 130 | } |
| 131 | |
| 132 | list_begin( head )[ size ] = value; |
| 133 | head->impl.size = size + 1; |
| 134 | |
| 135 | return head; |
| 136 | } |
| 137 | |
| 138 | |
| 139 | /* |
no test coverage detected