@@ -1532,7 +1532,7 @@ static inline int bcf_enc_size(kstring_t *s, int size, int type)
15321532 return 0 ;
15331533 }
15341534
1535- if (ks_resize (s , s -> l + 5 ) < 0 )
1535+ if (ks_resize (s , s -> l + 6 ) < 0 )
15361536 return -1 ;
15371537 uint8_t * p = (uint8_t * )s -> s + s -> l ;
15381538 * p ++ = 15 <<4 |type ;
@@ -1555,6 +1555,13 @@ static inline int bcf_enc_size(kstring_t *s, int size, int type)
15551555 return 0 ;
15561556}
15571557
1558+ static inline int bcf_enc_inttype (long x )
1559+ {
1560+ if (x <= BCF_MAX_BT_INT8 && x >= BCF_MIN_BT_INT8 ) return BCF_BT_INT8 ;
1561+ if (x <= BCF_MAX_BT_INT16 && x >= BCF_MIN_BT_INT16 ) return BCF_BT_INT16 ;
1562+ return BCF_BT_INT32 ;
1563+ }
1564+
15581565// INTERNAL - not to be assumed to be a part of public API
15591566// As per bcf_enc_size but kstring is already guaranteed to be big enough
15601567// and with size == 1.
@@ -1565,35 +1572,36 @@ static inline void bcf_enc_size1_(kstring_t *s, int type)
15651572 s -> l ++ ;
15661573}
15671574
1568- static inline int bcf_enc_inttype (long x )
1569- {
1570- if (x <= BCF_MAX_BT_INT8 && x >= BCF_MIN_BT_INT8 ) return BCF_BT_INT8 ;
1571- if (x <= BCF_MAX_BT_INT16 && x >= BCF_MIN_BT_INT16 ) return BCF_BT_INT16 ;
1572- return BCF_BT_INT32 ;
1573- }
1574-
15751575static inline int bcf_enc_int1 (kstring_t * s , int32_t x )
15761576{
15771577 if (ks_resize (s , s -> l + 5 ) < 0 )
15781578 return -1 ;
1579- uint8_t * p = (uint8_t * )s -> s + s -> l + 1 /*1 for size*/ ;
1579+ uint8_t * p = (uint8_t * )s -> s + s -> l ;
15801580
15811581 if (x == bcf_int32_vector_end ) {
1582- bcf_enc_size1_ (s , BCF_BT_INT8 );
1583- * p = bcf_int8_vector_end ; s -> l ++ ;
1582+ // An inline implementation of bcf_enc_size with size==1 and
1583+ // memory allocation already accounted for.
1584+ * p = (1 <<4 ) | BCF_BT_INT8 ;
1585+ p [1 ] = bcf_int8_vector_end ;
1586+ s -> l += 2 ;
15841587 } else if (x == bcf_int32_missing ) {
1585- bcf_enc_size1_ (s , BCF_BT_INT8 );
1586- * p = bcf_int8_missing ; s -> l ++ ;
1588+ * p = (1 <<4 ) | BCF_BT_INT8 ;
1589+ p [1 ] = bcf_int8_missing ;
1590+ s -> l += 2 ;
15871591 } else if (x <= BCF_MAX_BT_INT8 && x >= BCF_MIN_BT_INT8 ) {
1588- bcf_enc_size1_ (s , BCF_BT_INT8 );
1589- * p = x ; s -> l ++ ;
1592+ * p = (1 <<4 ) | BCF_BT_INT8 ;
1593+ p [1 ] = x ;
1594+ s -> l += 2 ;
15901595 } else if (x <= BCF_MAX_BT_INT16 && x >= BCF_MIN_BT_INT16 ) {
1591- bcf_enc_size1_ (s , BCF_BT_INT16 );
1592- i16_to_le (x , p ); s -> l += 2 ;
1596+ * p = (1 <<4 ) | BCF_BT_INT16 ;
1597+ i16_to_le (x , p + 1 );
1598+ s -> l += 3 ;
15931599 } else {
1594- bcf_enc_size1_ (s , BCF_BT_INT32 );
1595- i32_to_le (x , p ); s -> l += 4 ;
1600+ * p = (1 <<4 ) | BCF_BT_INT32 ;
1601+ i32_to_le (x , p + 1 );
1602+ s -> l += 5 ;
15961603 }
1604+
15971605 return 0 ;
15981606}
15991607
0 commit comments