length prefix morphism: generic calls to functions with C macro
This commit is contained in:
parent
62f0ff9eac
commit
dfa364bc0f
1 changed files with 9 additions and 9 deletions
|
@ -47,17 +47,17 @@ morph_seqseq_as_valsep_to_lenpfx (T: Type, Delim: T, EscKey: T)
|
|||
```
|
||||
length_prefix_nativeUInt64_array_nativeUInt64_clear( dst );
|
||||
|
||||
struct LengthPrefix_nativeUInt64_Array_nativeUInt8 * cur_item = NULL;
|
||||
LENGTH_PREFIX_ARRAY_TYPE( nativeUInt64, T ) * cur_item = NULL;
|
||||
|
||||
uint8_t const * start = &src->items[0];
|
||||
uint8_t const * cur = start;
|
||||
uint8_t const * end = &src->items[src->len];
|
||||
T const * start = &src->items[0];
|
||||
T const * cur = start;
|
||||
T const * end = &src->items[src->len];
|
||||
|
||||
while( cur < end ) {
|
||||
if( *cur == Delim || cur+1 == end ) {
|
||||
uint64_t len = cur - start;
|
||||
|
||||
cur_item = malloc( sizeof(uint64_t) + sizeof(uint8_t) * len );
|
||||
cur_item = malloc( sizeof(uint64_t) + sizeof(T) * len );
|
||||
cur_item->len = len;
|
||||
memcpy( cur_item->items, start, len );
|
||||
|
||||
|
@ -80,17 +80,17 @@ morph_seqeq_as_lenpfx_to_valsep (T: Type, Delim: T, EscKey: T)
|
|||
~ < ValueSep T Delim >
|
||||
~ < Seq~<LengthPrefix native.UInt64> T >
|
||||
```
|
||||
length_prefix_nativeUInt64_array_nativeUInt8_clear( dst );
|
||||
PRESCAN_LENGTH_PREFIX_CALL(nativeUInt64, T, clear)( dst );
|
||||
|
||||
for( uint64_t i = 0; i < src->len; ++i ) {
|
||||
LengthPrefix_nativeUInt64_Array_nativeUInt8_t * item = src->items[i];
|
||||
LENGTH_PREFIX_ARRAY_TYPE( nativeUInt64, T ) * item = src->items[i];
|
||||
|
||||
for( uint64_t j = 0; j < item->len; ++j ) {
|
||||
length_prefix_nativeUInt64_array_nativeUInt8_push( items->items[j] );
|
||||
PRESCAN_LENGTH_PREFIX_CALL( nativeUInt64, T, push )( items->items[j] );
|
||||
}
|
||||
|
||||
if( i+1 < src->len ) {
|
||||
length_prefix_nativeUInt64_array_nativeUInt8_push( Delim );
|
||||
PRESCAN_LENGTH_PREFIX_CALL( nativeUInt64, T, push )( Delim );
|
||||
}
|
||||
}
|
||||
```
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue