mirror of
https://github.com/jarun/nnn.git
synced 2025-01-24 17:56:41 +00:00
Invert optimization: allocate in a go
This commit is contained in:
parent
064f5ea998
commit
0159c08602
15
src/nnn.c
15
src/nnn.c
|
@ -1562,7 +1562,8 @@ static inline void findmarkentry(char *path, struct entry *dentp)
|
||||||
|
|
||||||
static void invertselbuf(char *path)
|
static void invertselbuf(char *path)
|
||||||
{
|
{
|
||||||
size_t len, endpos, offset = 0;
|
size_t len, endpos, shrinklen = 0, alloclen = 0;
|
||||||
|
size_t const pathlen = xstrlen(path);
|
||||||
char *found;
|
char *found;
|
||||||
int nmarked = 0, prev = 0;
|
int nmarked = 0, prev = 0;
|
||||||
struct entry *dentp;
|
struct entry *dentp;
|
||||||
|
@ -1580,6 +1581,7 @@ static void invertselbuf(char *path)
|
||||||
} else {
|
} else {
|
||||||
++nselected;
|
++nselected;
|
||||||
dentp->flags |= FILE_SELECTED;
|
dentp->flags |= FILE_SELECTED;
|
||||||
|
alloclen += pathlen + dentp->nlen;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
dentp->flags |= FILE_SCANNED;
|
dentp->flags |= FILE_SCANNED;
|
||||||
|
@ -1603,10 +1605,11 @@ static void invertselbuf(char *path)
|
||||||
}
|
}
|
||||||
|
|
||||||
--nselected;
|
--nselected;
|
||||||
offset += len; /* buffer size adjustment */
|
shrinklen += len; /* buffer size adjustment */
|
||||||
} else {
|
} else {
|
||||||
++nselected;
|
++nselected;
|
||||||
dentp->flags |= FILE_SELECTED;
|
dentp->flags |= FILE_SELECTED;
|
||||||
|
alloclen += pathlen + dentp->nlen;
|
||||||
}
|
}
|
||||||
scan = FALSE;
|
scan = FALSE;
|
||||||
}
|
}
|
||||||
|
@ -1658,7 +1661,13 @@ static void invertselbuf(char *path)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Buffer size adjustment */
|
/* Buffer size adjustment */
|
||||||
selbufpos -= offset;
|
selbufpos -= shrinklen;
|
||||||
|
|
||||||
|
if (alloclen > shrinklen) {
|
||||||
|
pselbuf = xrealloc(pselbuf, selbuflen + (alloclen - shrinklen));
|
||||||
|
if (!pselbuf)
|
||||||
|
errexit();
|
||||||
|
}
|
||||||
|
|
||||||
free(marked);
|
free(marked);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue