[vlc-commits] vlc_arrays: add vlc_dictionary_is_empty
Francois Cartegnie
git at videolan.org
Thu Jun 22 11:12:18 CEST 2017
vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Wed Jun 21 18:18:27 2017 +0200| [68588c1b84547fdd00a2ed942c0cbde079121d7b] | committer: Francois Cartegnie
vlc_arrays: add vlc_dictionary_is_empty
avoids walking every key/entry
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=68588c1b84547fdd00a2ed942c0cbde079121d7b
---
include/vlc_arrays.h | 10 ++++++++++
modules/codec/ttml/substtml.c | 2 +-
modules/control/dbus/dbus.c | 6 +++---
src/test/dictionary.c | 3 +++
4 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/include/vlc_arrays.h b/include/vlc_arrays.h
index 5e5ef45458..8c4419cb61 100644
--- a/include/vlc_arrays.h
+++ b/include/vlc_arrays.h
@@ -473,6 +473,16 @@ vlc_dictionary_keys_count( const vlc_dictionary_t * p_dict )
return count;
}
+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++ )
+ if( p_dict->p_entries[i] )
+ return false;
+ return true;
+}
+
static inline char **
vlc_dictionary_all_keys( const vlc_dictionary_t * p_dict )
{
diff --git a/modules/codec/ttml/substtml.c b/modules/codec/ttml/substtml.c
index 373dc24d62..84f13f5bab 100644
--- a/modules/codec/ttml/substtml.c
+++ b/modules/codec/ttml/substtml.c
@@ -519,7 +519,7 @@ static ttml_style_t * InheritTTMLStyles( ttml_context_t *p_ctx, tt_node_t *p_nod
DictMergeWithRegionID( p_ctx, psz_regionid, &merged );
}
- if( vlc_dictionary_keys_count( &merged ) && (p_ttml_style = ttml_style_New()) )
+ if( !vlc_dictionary_is_empty( &merged ) && (p_ttml_style = ttml_style_New()) )
{
DictToTTMLStyle( &merged, p_ttml_style );
}
diff --git a/modules/control/dbus/dbus.c b/modules/control/dbus/dbus.c
index 87be4d2472..5afe8bb782 100644
--- a/modules/control/dbus/dbus.c
+++ b/modules/control/dbus/dbus.c
@@ -616,13 +616,13 @@ static void ProcessEvents( intf_thread_t *p_intf,
free( p_events[i] );
}
- if( vlc_dictionary_keys_count( &player_properties ) )
+ if( !vlc_dictionary_is_empty( &player_properties ) )
PlayerPropertiesChangedEmit( p_intf, &player_properties );
- if( vlc_dictionary_keys_count( &tracklist_properties ) )
+ if( !vlc_dictionary_is_empty( &tracklist_properties ) )
TrackListPropertiesChangedEmit( p_intf, &tracklist_properties );
- if( vlc_dictionary_keys_count( &root_properties ) )
+ if( !vlc_dictionary_is_empty( &root_properties ) )
RootPropertiesChangedEmit( p_intf, &root_properties );
vlc_dictionary_clear( &player_properties, NULL, NULL );
diff --git a/src/test/dictionary.c b/src/test/dictionary.c
index 2e686e4859..44d1b50924 100644
--- a/src/test/dictionary.c
+++ b/src/test/dictionary.c
@@ -74,6 +74,7 @@ int main (void)
vlc_dictionary_init( &dict, 0 );
assert( vlc_dictionary_keys_count( &dict ) == 0 );
+ assert( vlc_dictionary_is_empty( &dict ) );
keys = vlc_dictionary_all_keys( &dict );
assert( keys && !keys[0] );
@@ -89,6 +90,7 @@ int main (void)
assert( !vlc_dictionary_has_key(&dict, our_keys[j]) );
}
+ assert( !vlc_dictionary_is_empty( &dict ) );
test_dictionary_validity( &dict, our_keys, size );
vlc_dictionary_remove_value_for_key( &dict, our_keys[size-1], NULL, NULL );
@@ -98,5 +100,6 @@ int main (void)
vlc_dictionary_clear( &dict, NULL, NULL );
assert( vlc_dictionary_keys_count( &dict ) == 0 );
+ assert( vlc_dictionary_is_empty( &dict ) );
return 0;
}
More information about the vlc-commits
mailing list