mirror of
https://github.com/davatorium/rofi.git
synced 2025-02-10 15:44:41 -05:00
[FileBrowser] Reduce number of re-allocs.
This commit is contained in:
parent
6ec5bfba64
commit
e3860c89e8
2 changed files with 22 additions and 15 deletions
|
@ -1071,15 +1071,15 @@ This property sets the distance between the packed widgets (both horizontally an
|
||||||
More dynamic spacing can be achieved by adding dummy widgets, for example to make one widget centered:
|
More dynamic spacing can be achieved by adding dummy widgets, for example to make one widget centered:
|
||||||
|
|
||||||
```
|
```
|
||||||
|--------------------------------------------|
|
|----------------------------------------------------|
|
||||||
| |-----------| |--------| |-----------| |
|
| |---------------| |--------| |---------------| |
|
||||||
| | dummy | | child | | dummy | |
|
| | dummy | | child | | dummy | |
|
||||||
| | expand: y | | | | expand: y | |
|
| | expand: true; | | | | expand: true; | |
|
||||||
| | | | | | | |
|
| | | | | | | |
|
||||||
| | | | | | | |
|
| | | | | | | |
|
||||||
| | | | | | | |
|
| | | | | | | |
|
||||||
| |-----------| |--------| |-----------| |
|
| |---------------| |--------| |---------------| |
|
||||||
|--------------------------------------------|
|
|----------------------------------------------------|
|
||||||
```
|
```
|
||||||
|
|
||||||
If both dummy widgets are set to expand, `child` will be centered. Depending on the `expand` flag of child the
|
If both dummy widgets are set to expand, `child` will be centered. Depending on the `expand` flag of child the
|
||||||
|
|
|
@ -92,6 +92,7 @@ typedef struct {
|
||||||
GFile *current_dir;
|
GFile *current_dir;
|
||||||
FBFile *array;
|
FBFile *array;
|
||||||
unsigned int array_length;
|
unsigned int array_length;
|
||||||
|
unsigned int array_length_real;
|
||||||
} FileBrowserModePrivateData;
|
} FileBrowserModePrivateData;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -119,6 +120,7 @@ static void free_list(FileBrowserModePrivateData *pd) {
|
||||||
g_free(pd->array);
|
g_free(pd->array);
|
||||||
pd->array = NULL;
|
pd->array = NULL;
|
||||||
pd->array_length = 0;
|
pd->array_length = 0;
|
||||||
|
pd->array_length_real = 0;
|
||||||
}
|
}
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
@ -205,6 +207,14 @@ static void set_time(FBFile *file) {
|
||||||
// g_free(path);
|
// g_free(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline static void fb_resize_array(FileBrowserModePrivateData *pd) {
|
||||||
|
if ((pd->array_length + 1) > pd->array_length_real) {
|
||||||
|
pd->array_length_real += 256;
|
||||||
|
pd->array =
|
||||||
|
g_realloc(pd->array, (pd->array_length_real + 1) * sizeof(FBFile));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void get_file_browser(Mode *sw) {
|
static void get_file_browser(Mode *sw) {
|
||||||
FileBrowserModePrivateData *pd =
|
FileBrowserModePrivateData *pd =
|
||||||
(FileBrowserModePrivateData *)mode_get_private_data(sw);
|
(FileBrowserModePrivateData *)mode_get_private_data(sw);
|
||||||
|
@ -218,8 +228,7 @@ static void get_file_browser(Mode *sw) {
|
||||||
struct dirent *rd = NULL;
|
struct dirent *rd = NULL;
|
||||||
while ((rd = readdir(dir)) != NULL) {
|
while ((rd = readdir(dir)) != NULL) {
|
||||||
if (g_strcmp0(rd->d_name, "..") == 0) {
|
if (g_strcmp0(rd->d_name, "..") == 0) {
|
||||||
pd->array =
|
fb_resize_array(pd);
|
||||||
g_realloc(pd->array, (pd->array_length + 1) * sizeof(FBFile));
|
|
||||||
// Rofi expects utf-8, so lets convert the filename.
|
// Rofi expects utf-8, so lets convert the filename.
|
||||||
pd->array[pd->array_length].name = g_strdup("..");
|
pd->array[pd->array_length].name = g_strdup("..");
|
||||||
pd->array[pd->array_length].path = NULL;
|
pd->array[pd->array_length].path = NULL;
|
||||||
|
@ -244,8 +253,7 @@ static void get_file_browser(Mode *sw) {
|
||||||
break;
|
break;
|
||||||
case DT_REG:
|
case DT_REG:
|
||||||
case DT_DIR:
|
case DT_DIR:
|
||||||
pd->array =
|
fb_resize_array(pd);
|
||||||
g_realloc(pd->array, (pd->array_length + 1) * sizeof(FBFile));
|
|
||||||
// Rofi expects utf-8, so lets convert the filename.
|
// Rofi expects utf-8, so lets convert the filename.
|
||||||
pd->array[pd->array_length].name =
|
pd->array[pd->array_length].name =
|
||||||
g_filename_to_utf8(rd->d_name, -1, NULL, NULL, NULL);
|
g_filename_to_utf8(rd->d_name, -1, NULL, NULL, NULL);
|
||||||
|
@ -266,8 +274,7 @@ static void get_file_browser(Mode *sw) {
|
||||||
pd->array_length++;
|
pd->array_length++;
|
||||||
break;
|
break;
|
||||||
case DT_LNK:
|
case DT_LNK:
|
||||||
pd->array =
|
fb_resize_array(pd);
|
||||||
g_realloc(pd->array, (pd->array_length + 1) * sizeof(FBFile));
|
|
||||||
// Rofi expects utf-8, so lets convert the filename.
|
// Rofi expects utf-8, so lets convert the filename.
|
||||||
pd->array[pd->array_length].name =
|
pd->array[pd->array_length].name =
|
||||||
g_filename_to_utf8(rd->d_name, -1, NULL, NULL, NULL);
|
g_filename_to_utf8(rd->d_name, -1, NULL, NULL, NULL);
|
||||||
|
|
Loading…
Add table
Reference in a new issue