mirror of
https://github.com/jarun/nnn.git
synced 2024-11-28 05:41:31 +00:00
realloc() 32 entries at a time
This commit is contained in:
parent
74a13c645d
commit
286a13d891
|
@ -48,7 +48,7 @@ I chose to fork because:
|
||||||
### Original features
|
### Original features
|
||||||
|
|
||||||
- Super-easy navigation
|
- Super-easy navigation
|
||||||
- Pre-defined associaitons for different file types
|
- Pre-defined associations for different file types
|
||||||
- Jump to home directory
|
- Jump to home directory
|
||||||
- Filter contents in current directory
|
- Filter contents in current directory
|
||||||
- Show/hide hidden files
|
- Show/hide hidden files
|
||||||
|
@ -108,8 +108,8 @@ The following top excerpt shows the difference in nnn and ncdu memory usage whil
|
||||||
|
|
||||||
```
|
```
|
||||||
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
|
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
|
||||||
6054 vaio 20 0 56768 45268 2300 S 0.0 0.9 0:02.82 ncdu
|
10406 vaio 20 0 53808 42284 2248 S 0.0 0.8 0:00.82 ncdu
|
||||||
10806 vaio 20 0 21228 8572 2432 S 0.0 0.2 0:00.07 nnn -d
|
10409 vaio 20 0 20452 9172 2356 S 0.0 0.2 0:00.83 nnn -d
|
||||||
```
|
```
|
||||||
|
|
||||||
### Installation
|
### Installation
|
||||||
|
|
49
nnn.c
49
nnn.c
|
@ -149,26 +149,6 @@ static void printmsg(char *);
|
||||||
static void printwarn(void);
|
static void printwarn(void);
|
||||||
static void printerr(int, char *);
|
static void printerr(int, char *);
|
||||||
|
|
||||||
static void *
|
|
||||||
xmalloc(size_t size)
|
|
||||||
{
|
|
||||||
void *p = malloc(size);
|
|
||||||
if (p == NULL)
|
|
||||||
printerr(1, "malloc");
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
static void *
|
|
||||||
xrealloc(void *p, size_t size)
|
|
||||||
{
|
|
||||||
p = realloc(p, size);
|
|
||||||
if (p == NULL)
|
|
||||||
printerr(1, "realloc");
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static rlim_t
|
static rlim_t
|
||||||
max_openfds()
|
max_openfds()
|
||||||
{
|
{
|
||||||
|
@ -1022,34 +1002,21 @@ dentfill(char *path, struct entry **dents,
|
||||||
if (dirp == NULL)
|
if (dirp == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
long pos = telldir(dirp);
|
|
||||||
while ((dp = readdir(dirp)) != NULL) {
|
|
||||||
if (filter(re, dp->d_name) == 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
n++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (filter(re, ".") != 0)
|
|
||||||
n--;
|
|
||||||
if (filter(re, "..") != 0)
|
|
||||||
n--;
|
|
||||||
if (n == 0)
|
|
||||||
return n;
|
|
||||||
|
|
||||||
*dents = xmalloc(n * sizeof(**dents));
|
|
||||||
n = 0;
|
|
||||||
|
|
||||||
seekdir(dirp, pos);
|
|
||||||
|
|
||||||
while ((dp = readdir(dirp)) != NULL) {
|
while ((dp = readdir(dirp)) != NULL) {
|
||||||
/* Skip self and parent */
|
/* Skip self and parent */
|
||||||
if ((dp->d_name[0] == '.' && (dp->d_name[1] == '\0' ||
|
if ((dp->d_name[0] == '.' && (dp->d_name[1] == '\0' ||
|
||||||
(dp->d_name[1] == '.' && dp->d_name[2] == '\0'))))
|
(dp->d_name[1] == '.' && dp->d_name[2] == '\0'))))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (filter(re, dp->d_name) == 0)
|
if (filter(re, dp->d_name) == 0)
|
||||||
continue;
|
continue;
|
||||||
//*dents = xrealloc(*dents, (n + 1) * sizeof(**dents));
|
|
||||||
|
if (((n >> 5) << 5) == n) {
|
||||||
|
*dents = realloc(*dents, (n + 32) * sizeof(**dents));
|
||||||
|
if (*dents == NULL)
|
||||||
|
printerr(1, "realloc");
|
||||||
|
}
|
||||||
|
|
||||||
xstrlcpy((*dents)[n].name, dp->d_name, sizeof((*dents)[n].name));
|
xstrlcpy((*dents)[n].name, dp->d_name, sizeof((*dents)[n].name));
|
||||||
/* Get mode flags */
|
/* Get mode flags */
|
||||||
mkpath(path, dp->d_name, newpath, sizeof(newpath));
|
mkpath(path, dp->d_name, newpath, sizeof(newpath));
|
||||||
|
|
Loading…
Reference in a new issue