mirror of
https://github.com/radareorg/radare2.git
synced 2025-02-02 19:55:14 +00:00
Optimize r_file_proc_size() reading by blocks instead of chars ##util (#17119)
* Optimize r_file_proc_size() reading by blocks instead of chars ##util For /proc/self/maps this is almost 2x faster, will be much faster on bigger files * Make it static, it's not even defined in r_file.h * Rename `r_file_proc_size()` into `procfile_size()` Co-authored-by: pancake <pancake@nopcode.org> Co-authored-by: Anton Kochkov <xvilka@gmail.com>
This commit is contained in:
parent
a64cd12951
commit
e56c784791
@ -181,11 +181,12 @@ R_API bool r_file_exists(const char *str) {
|
||||
return S_IFREG == (S_IFREG & buf.st_mode);
|
||||
}
|
||||
|
||||
R_API long r_file_proc_size(FILE *fd) {
|
||||
static inline long procfile_size(FILE *fd) {
|
||||
char buf[1024];
|
||||
long size = 0;
|
||||
while (fgetc (fd) != EOF) {
|
||||
size++;
|
||||
}
|
||||
do {
|
||||
size += fread (buf, 1, sizeof (buf), fd);
|
||||
} while (!feof (fd));
|
||||
return size;
|
||||
}
|
||||
|
||||
@ -369,7 +370,7 @@ R_API char *r_file_slurp(const char *str, R_NULLABLE size_t *usz) {
|
||||
if (r_file_is_regular (str)) {
|
||||
/* proc file */
|
||||
fseek (fd, 0, SEEK_SET);
|
||||
sz = r_file_proc_size (fd);
|
||||
sz = procfile_size (fd);
|
||||
} else {
|
||||
sz = 65536;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user