@ -66,32 +66,13 @@ void grpc_slice_unref(grpc_slice slice) {
}
}
}
}
namespace grpc_core {
/* grpc_slice_from_static_string support structure - a refcount that does
/* grpc_slice_from_static_string support structure - a refcount that does
nothing */
nothing */
static grpc_slice_refcount NoopRefcount =
grpc_slice_refcount kNoopRefcount ( grpc_slice_refcount : : Type : : NOP ) ;
grpc_slice_refcount ( grpc_slice_refcount : : Type : : NOP ) ;
static_assert ( std : : is_trivially_destructible < decltype ( kNoopRefcount ) > : : value ,
" kNoopRefcount must be trivially destructible. " ) ;
size_t grpc_slice_memory_usage ( grpc_slice s ) {
if ( s . refcount = = nullptr | | s . refcount = = & NoopRefcount ) {
return 0 ;
} else {
return s . data . refcounted . length ;
}
}
grpc_slice grpc_slice_from_static_buffer ( const void * s , size_t len ) {
grpc_slice slice ;
slice . refcount = & NoopRefcount ;
slice . data . refcounted . bytes = ( uint8_t * ) s ;
slice . data . refcounted . length = len ;
return slice ;
}
grpc_slice grpc_slice_from_static_string ( const char * s ) {
return grpc_slice_from_static_buffer ( s , strlen ( s ) ) ;
}
namespace grpc_core {
/* grpc_slice_new support structures - we create a refcount object extended
/* grpc_slice_new support structures - we create a refcount object extended
with the user provided data pointer & destroy function */
with the user provided data pointer & destroy function */
@ -122,6 +103,22 @@ class NewSliceRefcount {
} // namespace grpc_core
} // namespace grpc_core
size_t grpc_slice_memory_usage ( grpc_slice s ) {
if ( s . refcount = = nullptr | | s . refcount = = & grpc_core : : kNoopRefcount ) {
return 0 ;
} else {
return s . data . refcounted . length ;
}
}
grpc_slice grpc_slice_from_static_buffer ( const void * s , size_t len ) {
return grpc_slice_from_static_buffer_internal ( s , len ) ;
}
grpc_slice grpc_slice_from_static_string ( const char * s ) {
return grpc_slice_from_static_buffer_internal ( s , strlen ( s ) ) ;
}
grpc_slice grpc_slice_new_with_user_data ( void * p , size_t len ,
grpc_slice grpc_slice_new_with_user_data ( void * p , size_t len ,
void ( * destroy ) ( void * ) ,
void ( * destroy ) ( void * ) ,
void * user_data ) {
void * user_data ) {
@ -375,10 +372,10 @@ grpc_slice grpc_slice_split_tail_maybe_ref(grpc_slice* source, size_t split,
switch ( ref_whom ) {
switch ( ref_whom ) {
case GRPC_SLICE_REF_TAIL :
case GRPC_SLICE_REF_TAIL :
tail . refcount = source - > refcount - > sub_refcount ( ) ;
tail . refcount = source - > refcount - > sub_refcount ( ) ;
source - > refcount = & NoopRefcount ;
source - > refcount = & grpc_core : : k NoopRefcount;
break ;
break ;
case GRPC_SLICE_REF_HEAD :
case GRPC_SLICE_REF_HEAD :
tail . refcount = & NoopRefcount ;
tail . refcount = & grpc_core : : k NoopRefcount;
source - > refcount = source - > refcount - > sub_refcount ( ) ;
source - > refcount = source - > refcount - > sub_refcount ( ) ;
break ;
break ;
case GRPC_SLICE_REF_BOTH :
case GRPC_SLICE_REF_BOTH :