//====================================================================== // // memory release // //====================================================================== void carver:: release( void *p ) throw() { if( p != NULL) { slice *s = slice::release(p); assert( list_.owns(s) ); if( s->is_empty() ) { if( free_ ) { assert( free_->is_empty() ); if( free_->entry_ < s->entry_ ) { cswap<slice*>( free_, s); } assert( free_->entry_ > s->entry_); destruct( list_.unlink(free_) ); if( pool_.size >= max_in_pool ) { release_slice(free_); } else { pool_.store( free_ ); } } free_ = s; } } }
slice * make_slice( uint64_t start, uint64_t count, const String * refname ) { slice * res = calloc( 1, sizeof *res ); if ( res != NULL ) { rc_t rc = StringCopy( &res->refname, refname ); if ( rc == 0 ) { res->start = start; res->count = count; res->end = start + count; } else { release_slice( res ); res = NULL; } } return res; }
rc_t get_slices( const Args * args, const char *option, Vector * slices ) { uint32_t count, i; rc_t rc = ArgsOptionCount( args, option, &count ); for ( i = 0; i < count && rc == 0; ++i ) { const char * value; rc = ArgsOptionValue( args, option, i, ( const void ** )&value ); if ( rc == 0 && value != NULL ) { String S; StringInitCString( &S, value ); { slice * s = make_slice_from_str( &S ); rc = VectorAppend( slices, NULL, s ); if ( rc != 0 ) release_slice( s ); } } } return rc; }
static inline void destroy_slice( slice *s ) throw() { assert( NULL != s ); destruct(s); release_slice(s); }