On Tue, Apr 16, 2024 at 4:10 AM Jody Bruchon <j...@jodybruchon.com> wrote: > > This revision reduces code size in concat_path_file_fast() by 19 bytes. It > also applies the new get_d_namlen() optimization to a readdir() loop in > runit/svlogd.c. > > If there are any changes that need to be made for inclusion then please let > me know as soon as possible. I'd like to finish this project up. If the > old/slow and new/fast code should be chosen with a compile-time config option > then I'm happy to do that as well.
+#elif defined _DIRENT_HAVE_D_RECLEN + const size_t base = (sizeof(struct dirent) - sizeof(((struct dirent *)0)->d_name)) - offsetof(struct dirent, d_name) - 1; + size_t skip; + + skip = dirent->d_reclen - (sizeof(struct dirent) - sizeof(((struct dirent *)0)->d_name)); + if (skip > 0) skip -= base; + return skip + strlen(dirent->d_name + skip); What is it doing? (Probably needs a comment). Shouldn't this be just + const size_t prefix_sz = offsetof(struct dirent, d_name); + return de->d_reclen - prefix_sz; ? + const char *filename = dirp->d_name; ... + while (*filename == '/') { + filename++; + namelen--; + } d_name's never contain slashes. It's not allowed in unix filenames. + buf = (char *)malloc(end_offset + 1); + if (!buf) return NULL; Use xmalloc. + if (dirp->d_name && DOT_OR_DOTDOT(dirp->d_name)) + return NULL; dirp->d_name is never NULL, don't check for that. But the biggest problem is this: I don't see much improvement in the time it takes to copy data. Here I copy a Linux kernel tree, 1450M mbytes, 89679 files, on tmpfs ("ramdisk"): $ time ./busybox_old cp -a linux linux1; rm -rf linux1; time ./busybox cp -a linux linux1; rm -rf linux1 real 0m10.464s user 0m1.067s <<< almost the same sys 0m8.558s real 0m11.070s user 0m0.959s <<< almost the same sys 0m9.204s and the time, even on tmpfs, is heavily dominated by actual copying, not constructing filenames. _______________________________________________ busybox mailing list busybox@busybox.net https://lists.busybox.net/mailman/listinfo/busybox