[vlc-commits] [Git][videolan/vlc][master] 2 commits: vlc_arrays: use size_t for hash output and size
Felix Paul Kühne (@fkuehne)
gitlab at videolan.org
Thu Mar 13 15:42:33 UTC 2025
Felix Paul Kühne pushed to branch master at VideoLAN / VLC
Commits:
47471145 by Alexandre Janniaux at 2025-03-13T15:24:20+00:00
vlc_arrays: use size_t for hash output and size
The output value is bounded by the size parameter, and is used for
indexing elements in arrays.
- - - - -
1ff33faa by Alexandre Janniaux at 2025-03-13T15:24:20+00:00
vlc_arrays: use size_t for dictionaries
- - - - -
4 changed files:
- include/vlc_arrays.h
- modules/codec/ttml/genttml.c
- modules/codec/ttml/substtml.c
- modules/demux/mpeg/ts.c
Changes:
=====================================
include/vlc_arrays.h
=====================================
@@ -381,7 +381,7 @@ static inline void vlc_array_remove( vlc_array_t *ar, size_t idx )
* fast and not suck too much. This one is pretty fast and did 0 collisions
* in wenglish's dictionary.
*/
-static inline uint64_t DictHash( const char *psz_string, int hashsize )
+static inline size_t DictHash(const char *psz_string, size_t hashsize)
{
uint64_t i_hash = 0;
if( psz_string )
@@ -405,13 +405,13 @@ typedef struct vlc_dictionary_entry_t
typedef struct vlc_dictionary_t
{
- int i_size;
+ size_t i_size;
vlc_dictionary_entry_t ** p_entries;
} vlc_dictionary_t;
static void * const kVLCDictionaryNotFound = NULL;
-static inline void vlc_dictionary_init( vlc_dictionary_t * p_dict, int i_size )
+static inline void vlc_dictionary_init(vlc_dictionary_t * p_dict, size_t i_size)
{
p_dict->p_entries = NULL;
@@ -430,7 +430,7 @@ static inline void vlc_dictionary_clear( vlc_dictionary_t * p_dict,
{
if( p_dict->p_entries )
{
- for( int i = 0; i < p_dict->i_size; i++ )
+ for (size_t i = 0; i < p_dict->i_size; i++)
{
vlc_dictionary_entry_t * p_current, * p_next;
p_current = p_dict->p_entries[i];
@@ -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 );
+ size_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 );
+ size_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 )
@@ -488,11 +488,11 @@ vlc_dictionary_value_for_key( const vlc_dictionary_t * p_dict, const char * psz_
return kVLCDictionaryNotFound;
}
-static inline int
+static inline size_t
vlc_dictionary_keys_count( const vlc_dictionary_t * p_dict )
{
vlc_dictionary_entry_t * p_entry;
- int i, count = 0;
+ size_t i, count = 0;
if( !p_dict->p_entries )
return 0;
@@ -508,7 +508,7 @@ static inline bool
vlc_dictionary_is_empty( const vlc_dictionary_t * p_dict )
{
if( p_dict->p_entries )
- for( int i = 0; i < p_dict->i_size; i++ )
+ for (size_t i = 0; i < p_dict->i_size; i++)
if( p_dict->p_entries[i] )
return false;
return true;
@@ -519,7 +519,7 @@ vlc_dictionary_all_keys( const vlc_dictionary_t * p_dict )
{
vlc_dictionary_entry_t * p_entry;
char ** ppsz_ret;
- int i, count = vlc_dictionary_keys_count( p_dict );
+ size_t i, count = vlc_dictionary_keys_count(p_dict);
ppsz_ret = (char**)malloc(sizeof(char *) * (count + 1));
if( unlikely(!ppsz_ret) )
@@ -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 );
+ size_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));
@@ -560,8 +560,8 @@ vlc_dictionary_insert_impl_( vlc_dictionary_t * p_dict, const char * psz_key,
{
/* Here it starts to be not good, rebuild a bigger dictionary */
struct vlc_dictionary_t new_dict;
- int i_new_size = ( (p_dict->i_size+2) * 3) / 2; /* XXX: this need tuning */
- int i;
+ size_t i_new_size = (p_dict->i_size + 2) * 3 / 2; /* XXX: this need tuning */
+ size_t i;
vlc_dictionary_init( &new_dict, i_new_size );
for( i = 0; i < p_dict->i_size; i++ )
{
@@ -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 );
+ size_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;
=====================================
modules/codec/ttml/genttml.c
=====================================
@@ -89,7 +89,7 @@ void tt_node_AttributesToText( struct vlc_memstream *p_stream, const tt_node_t*
{
bool b_timed_node = false;
const vlc_dictionary_t* p_attr_dict = &p_node->attr_dict;
- for( int i = 0; i < p_attr_dict->i_size; ++i )
+ for (size_t i = 0; i < p_attr_dict->i_size; ++i)
{
for ( vlc_dictionary_entry_t* p_entry = p_attr_dict->p_entries[i];
p_entry != NULL; p_entry = p_entry->p_next )
=====================================
modules/codec/ttml/substtml.c
=====================================
@@ -584,7 +584,7 @@ static void FillTTMLStyle( const char *psz_attr, const char *psz_namespace,
static void DictionaryMerge( const vlc_dictionary_t *p_src, vlc_dictionary_t *p_dst,
bool b_override )
{
- for( int i = 0; i < p_src->i_size; ++i )
+ for (size_t i = 0; i < p_src->i_size; ++i)
{
for ( const vlc_dictionary_entry_t* p_entry = p_src->p_entries[i];
p_entry != NULL; p_entry = p_entry->p_next )
@@ -677,7 +677,7 @@ static void DictToTTMLStyle( ttml_context_t *p_ctx, tt_namespaces_t *p_nss,
const vlc_dictionary_t *p_dict,
ttml_style_t *p_ttml_style )
{
- for( int i = 0; i < p_dict->i_size; ++i )
+ for (size_t i = 0; i < p_dict->i_size; ++i)
{
for ( vlc_dictionary_entry_t* p_entry = p_dict->p_entries[i];
p_entry != NULL; p_entry = p_entry->p_next )
@@ -827,7 +827,7 @@ static ttml_region_t *GetTTMLRegion( ttml_context_t *p_ctx, tt_namespaces_t *p_n
if( (p_region = ttml_region_New( false )) )
{
/* Fill from its own attributes */
- for( int i = 0; i < merged.i_size; ++i )
+ for (size_t i = 0; i < merged.i_size; ++i)
{
for ( vlc_dictionary_entry_t* p_entry = merged.p_entries[i];
p_entry != NULL; p_entry = p_entry->p_next )
@@ -1119,7 +1119,7 @@ static ttml_region_t *GenerateRegions( tt_namespaces_t *p_nss, tt_node_t *p_root
vlc_dictionary_init( &context.regions, 1 );
ConvertNodesToRegionContent( &context, p_nss, p_bodynode, NULL, NULL, playbacktime );
- for( int i = 0; i < context.regions.i_size; ++i )
+ for (size_t i = 0; i < context.regions.i_size; ++i)
{
for ( const vlc_dictionary_entry_t* p_entry = context.regions.p_entries[i];
p_entry != NULL; p_entry = p_entry->p_next )
=====================================
modules/demux/mpeg/ts.c
=====================================
@@ -1222,7 +1222,7 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
return VLC_EGENERIC;
*pi_int = 0;
- for( int i = 0; i < p_sys->attachments.i_size; i++ )
+ for (size_t i = 0; i < p_sys->attachments.i_size; i++)
{
for( vlc_dictionary_entry_t *p_entry = p_sys->attachments.p_entries[i];
p_entry; p_entry = p_entry->p_next )
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/a0731bc13cccfa64eaf377e41c7550a4ed91694b...1ff33faabcd6ee6a5912298b6a1737a97a95af98
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/a0731bc13cccfa64eaf377e41c7550a4ed91694b...1ff33faabcd6ee6a5912298b6a1737a97a95af98
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list