[patches] [PATCH 1/4] tuple: move tuple_extract_key functions to a separate .cc file

Vladimir Davydov vdavydov.dev at gmail.com
Sat Feb 17 21:45:46 MSK 2018


On Tue, Feb 13, 2018 at 06:28:35PM +0300, Vladislav Shpilevoy wrote:
> Needed for #2048

Please explain in the comment why exactly you need this.
(I assume it has something to do with templates, right?)

> --- a/src/box/index.h
> +++ b/src/box/index.h
> @@ -195,6 +195,20 @@ ssize_t
>  box_index_count(uint32_t space_id, uint32_t index_id, int type,
>  		const char *key, const char *key_end);
>  
> +/**
> + * Extract key from tuple according to key definition of given
> + * index. Returned buffer is allocated on box_txn_alloc() with
> + * this key.
> + * @param tuple Tuple from which need to extract key.
> + * @param space_id Space identifier.
> + * @param index_id Index identifier.
> + * @retval not NULL Success
> + * @retval     NULL Memory Allocation error
> + */
> +char *
> +box_tuple_extract_key(const box_tuple_t *tuple, uint32_t space_id,
> +		      uint32_t index_id, uint32_t *key_size);
> +

Shouldn't it be in tuple_extract_key.h?

> diff --git a/src/box/key_def.h b/src/box/key_def.h
> index 201863f5a..d90859196 100644
> --- a/src/box/key_def.h
> +++ b/src/box/key_def.h
> @@ -374,6 +374,45 @@ key_part_check_compatibility(const struct key_part *old_parts,
>  			     const struct key_part *new_parts,
>  			     uint32_t new_part_count);
>  
> +/**
> + * Extract key from tuple by given key definition and return
> + * buffer allocated on box_txn_alloc with this key. This function
> + * has O(n) complexity, where n is the number of key parts.
> + * @param tuple - tuple from which need to extract key
> + * @param key_def - definition of key that need to extract
> + * @param key_size - here will be size of extracted key
> + *
> + * @retval not NULL Success
> + * @retval NULL     Memory allocation error
> + */
> +static inline char *
> +tuple_extract_key(const struct tuple *tuple, const struct key_def *key_def,
> +		  uint32_t *key_size)
> +{
> +	return key_def->tuple_extract_key(tuple, key_def, key_size);
> +}
> +
> +/**
> + * Extract key from raw msgpuck by given key definition and return
> + * buffer allocated on box_txn_alloc with this key.
> + * This function has O(n*m) complexity, where n is the number of key parts
> + * and m is the tuple size.
> + * @param data - msgpuck data from which need to extract key
> + * @param data_end - pointer at the end of data
> + * @param key_def - definition of key that need to extract
> + * @param key_size - here will be size of extracted key
> + *
> + * @retval not NULL Success
> + * @retval NULL     Memory allocation error
> + */
> +static inline char *
> +tuple_extract_key_raw(const char *data, const char *data_end,
> +		      const struct key_def *key_def, uint32_t *key_size)
> +{
> +	return key_def->tuple_extract_key_raw(data, data_end, key_def,
> +					      key_size);
> +}
> +

Again, why are these two defined here rather than in
tuple_extract_key.h?

> diff --git a/src/box/tuple_extract_key.cc b/src/box/tuple_extract_key.cc
> new file mode 100644
> index 000000000..a83e9dfc4
> --- /dev/null
> +++ b/src/box/tuple_extract_key.cc
> @@ -0,0 +1,197 @@
> +#include "tuple_extract_key.h"
> +#include "tuple.h"
> +#include "fiber.h"

Copyright's missing.



More information about the Tarantool-patches mailing list