mirror of
https://github.com/davatorium/rofi.git
synced 2025-02-17 15:45:56 -05:00
[Run] Filter out duplicates. Issue #86
This commit is contained in:
parent
8046fbec08
commit
2e0d79d73e
1 changed files with 46 additions and 5 deletions
|
@ -112,6 +112,16 @@ static int sort_func ( const void *a, const void *b )
|
||||||
{
|
{
|
||||||
const char *astr = *( const char * const * ) a;
|
const char *astr = *( const char * const * ) a;
|
||||||
const char *bstr = *( const char * const * ) b;
|
const char *bstr = *( const char * const * ) b;
|
||||||
|
|
||||||
|
if ( astr == NULL && bstr == NULL ) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else if ( astr == NULL ) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else if ( bstr == NULL ) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
return strcasecmp ( astr, bstr );
|
return strcasecmp ( astr, bstr );
|
||||||
}
|
}
|
||||||
static char ** get_apps ( unsigned int *length )
|
static char ** get_apps ( unsigned int *length )
|
||||||
|
@ -187,6 +197,7 @@ static char ** get_apps ( unsigned int *length )
|
||||||
}
|
}
|
||||||
g_free ( path );
|
g_free ( path );
|
||||||
#ifdef TIMING
|
#ifdef TIMING
|
||||||
|
{
|
||||||
clock_gettime ( CLOCK_REALTIME, &stop );
|
clock_gettime ( CLOCK_REALTIME, &stop );
|
||||||
|
|
||||||
if ( stop.tv_sec != start.tv_sec ) {
|
if ( stop.tv_sec != start.tv_sec ) {
|
||||||
|
@ -195,6 +206,36 @@ static char ** get_apps ( unsigned int *length )
|
||||||
|
|
||||||
long diff = stop.tv_nsec - start.tv_nsec;
|
long diff = stop.tv_nsec - start.tv_nsec;
|
||||||
printf ( "Time elapsed: %ld us\n", diff / 1000 );
|
printf ( "Time elapsed: %ld us\n", diff / 1000 );
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
unsigned int removed = 0;
|
||||||
|
for ( unsigned int index = num_favorites; index < ( ( *length ) - 1 ); index++ ) {
|
||||||
|
if ( strcmp ( retv[index], retv[index + 1] ) == 0 ) {
|
||||||
|
g_free ( retv[index] );
|
||||||
|
retv[index] = NULL;
|
||||||
|
removed++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if ( ( *length ) > num_favorites ) {
|
||||||
|
qsort ( &retv[num_favorites], ( *length ) - num_favorites, sizeof ( char* ), sort_func );
|
||||||
|
}
|
||||||
|
// Reduce array length;
|
||||||
|
( *length ) -= removed;
|
||||||
|
|
||||||
|
#ifdef TIMING
|
||||||
|
{
|
||||||
|
clock_gettime ( CLOCK_REALTIME, &stop );
|
||||||
|
|
||||||
|
if ( stop.tv_sec != start.tv_sec ) {
|
||||||
|
stop.tv_nsec += ( stop.tv_sec - start.tv_sec ) * 1e9;
|
||||||
|
}
|
||||||
|
|
||||||
|
long diff = stop.tv_nsec - start.tv_nsec;
|
||||||
|
printf ( "Time elapsed: %ld us\n", diff / 1000 );
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
return retv;
|
return retv;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue