| 89 | */ |
| 90 | |
| 91 | static char * allocate( size_t n ) |
| 92 | { |
| 93 | #ifdef BJAM_NEWSTR_NO_ALLOCATE |
| 94 | return (char *)BJAM_MALLOC( n ); |
| 95 | #else |
| 96 | /* See if we can grab storage from an existing block. */ |
| 97 | size_t remaining = storage_finish - storage_start; |
| 98 | n = ( ( n + ALLOC_ALIGNMENT - 1 ) / ALLOC_ALIGNMENT ) * ALLOC_ALIGNMENT; |
| 99 | if ( remaining >= n ) |
| 100 | { |
| 101 | char * result = storage_start; |
| 102 | storage_start += n; |
| 103 | return result; |
| 104 | } |
| 105 | else /* Must allocate a new block. */ |
| 106 | { |
| 107 | strblock * new_block; |
| 108 | size_t nalloc = n; |
| 109 | if ( nalloc < STRING_BLOCK ) |
| 110 | nalloc = STRING_BLOCK; |
| 111 | |
| 112 | /* Allocate a new block and link into the chain. */ |
| 113 | new_block = (strblock *)BJAM_MALLOC( offsetof( strblock, data[ 0 ] ) + |
| 114 | nalloc * sizeof( new_block->data[ 0 ] ) ); |
| 115 | if ( new_block == 0 ) |
| 116 | return 0; |
| 117 | new_block->next = strblock_chain; |
| 118 | strblock_chain = new_block; |
| 119 | |
| 120 | /* Take future allocations out of the larger remaining space. */ |
| 121 | if ( remaining < nalloc - n ) |
| 122 | { |
| 123 | storage_start = new_block->data + n; |
| 124 | storage_finish = new_block->data + nalloc; |
| 125 | } |
| 126 | return new_block->data; |
| 127 | } |
| 128 | #endif |
| 129 | } |
| 130 | |
| 131 | |
| 132 | static unsigned int hash_keyval( char const * key, int const size ) |
no outgoing calls