[vlc-devel] [PATCH 1/6] vlc_arrays.h: Dictionary: Use the correct type to store hash

Steve Lhomme robux4 at ycbcr.xyz
Fri Dec 4 08:04:19 CET 2020


Given the result of DictHash is used as a table index, shoudln't it be 
better to use size_t (as the return value and the i_pos values). Even at 
32 bits that seems like a diverse enough range, especially since there's 
always a modulo on the size of the dictionnary, giving small values anyway.

On 2020-12-03 15:33, Hugo Beauzée-Luyssen wrote:
> ---
>   include/vlc_arrays.h | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/include/vlc_arrays.h b/include/vlc_arrays.h
> index b558422f93..97959a6f8a 100644
> --- a/include/vlc_arrays.h
> +++ b/include/vlc_arrays.h
> @@ -456,7 +456,7 @@ vlc_dictionary_has_key( const vlc_dictionary_t * p_dict, const char * psz_key )
>       if( !p_dict->p_entries )
>           return 0;
>   
> -    int i_pos = DictHash( psz_key, p_dict->i_size );
> +    uint64_t i_pos = DictHash( psz_key, p_dict->i_size );
>       const vlc_dictionary_entry_t * p_entry = p_dict->p_entries[i_pos];
>       for( ; p_entry != NULL; p_entry = p_entry->p_next )
>       {
> @@ -472,7 +472,7 @@ vlc_dictionary_value_for_key( const vlc_dictionary_t * p_dict, const char * psz_
>       if( !p_dict->p_entries )
>           return kVLCDictionaryNotFound;
>   
> -    int i_pos = DictHash( psz_key, p_dict->i_size );
> +    uint64_t i_pos = DictHash( psz_key, p_dict->i_size );
>       vlc_dictionary_entry_t * p_entry = p_dict->p_entries[i_pos];
>   
>       if( !p_entry )
> @@ -542,7 +542,7 @@ vlc_dictionary_insert_impl_( vlc_dictionary_t * p_dict, const char * psz_key,
>       if( !p_dict->p_entries )
>           vlc_dictionary_init( p_dict, 1 );
>   
> -    int i_pos = DictHash( psz_key, p_dict->i_size );
> +    uint64_t i_pos = DictHash( psz_key, p_dict->i_size );
>       vlc_dictionary_entry_t * p_entry;
>   
>       p_entry = (vlc_dictionary_entry_t *)malloc(sizeof(*p_entry));
> @@ -596,7 +596,7 @@ vlc_dictionary_remove_value_for_key( const vlc_dictionary_t * p_dict, const char
>       if( !p_dict->p_entries )
>           return;
>   
> -    int i_pos = DictHash( psz_key, p_dict->i_size );
> +    uint64_t i_pos = DictHash( psz_key, p_dict->i_size );
>       vlc_dictionary_entry_t * p_entry = p_dict->p_entries[i_pos];
>       vlc_dictionary_entry_t * p_prev;
>   
> -- 
> 2.29.2
> 
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel
> 


More information about the vlc-devel mailing list