From 4fce4fa7c344592dbd961d712f1bae45b6afd5dc Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Sun, 12 Sep 2021 09:45:09 +0300 Subject: [PATCH] sftpfs: trivial optimization. * (sftpfs_opendir): call sftpfs_fix_filename() before loop. * (sftpfs_mkdir): likewise. * (sftpfs_rmdir): likewise. * (sftpfs_open_file): likewise. * (sftpfs_stat_init): likewise. * (sftpfs_readlink): likewise. * (sftpfs_utime): likewise. * (sftpfs_chmod): likewise. * (sftpfs_unlink): likewise. * (sftpfs_rename): likewise. Signed-off-by: Andrew Borodin --- src/vfs/sftpfs/dir.c | 20 +++++++++---------- src/vfs/sftpfs/file.c | 6 +++--- src/vfs/sftpfs/internal.c | 42 +++++++++++++++++---------------------- 3 files changed, 30 insertions(+), 38 deletions(-) diff --git a/src/vfs/sftpfs/dir.c b/src/vfs/sftpfs/dir.c index 568827433..6cbfd0628 100644 --- a/src/vfs/sftpfs/dir.c +++ b/src/vfs/sftpfs/dir.c @@ -70,6 +70,7 @@ sftpfs_opendir (const vfs_path_t * vpath, GError ** mcerror) sftpfs_super_t *sftpfs_super; const vfs_path_element_t *path_element; LIBSSH2_SFTP_HANDLE *handle; + const GString *fixfname; mc_return_val_if_error (mcerror, NULL); @@ -80,13 +81,12 @@ sftpfs_opendir (const vfs_path_t * vpath, GError ** mcerror) sftpfs_super = SFTP_SUPER (super); + fixfname = sftpfs_fix_filename (path_element->path); + while (TRUE) { - const GString *fixfname; int libssh_errno; - fixfname = sftpfs_fix_filename (path_element->path); - handle = libssh2_sftp_open_ex (sftpfs_super->sftp_session, fixfname->str, fixfname->len, 0, 0, LIBSSH2_SFTP_OPENDIR); @@ -177,6 +177,7 @@ sftpfs_mkdir (const vfs_path_t * vpath, mode_t mode, GError ** mcerror) struct vfs_s_super *super; sftpfs_super_t *sftpfs_super; const vfs_path_element_t *path_element; + const GString *fixfname; mc_return_val_if_error (mcerror, -1); @@ -192,12 +193,10 @@ sftpfs_mkdir (const vfs_path_t * vpath, mode_t mode, GError ** mcerror) if (sftpfs_super->sftp_session == NULL) return -1; + fixfname = sftpfs_fix_filename (path_element->path); + do { - const GString *fixfname; - - fixfname = sftpfs_fix_filename (path_element->path); - res = libssh2_sftp_mkdir_ex (sftpfs_super->sftp_session, fixfname->str, fixfname->len, mode); if (res >= 0) @@ -227,6 +226,7 @@ sftpfs_rmdir (const vfs_path_t * vpath, GError ** mcerror) struct vfs_s_super *super; sftpfs_super_t *sftpfs_super; const vfs_path_element_t *path_element; + const GString *fixfname; mc_return_val_if_error (mcerror, -1); @@ -242,12 +242,10 @@ sftpfs_rmdir (const vfs_path_t * vpath, GError ** mcerror) if (sftpfs_super->sftp_session == NULL) return -1; + fixfname = sftpfs_fix_filename (path_element->path); + do { - const GString *fixfname; - - fixfname = sftpfs_fix_filename (path_element->path); - res = libssh2_sftp_rmdir_ex (sftpfs_super->sftp_session, fixfname->str, fixfname->len); if (res >= 0) break; diff --git a/src/vfs/sftpfs/file.c b/src/vfs/sftpfs/file.c index 6ef92b832..bd1bb4ee6 100644 --- a/src/vfs/sftpfs/file.c +++ b/src/vfs/sftpfs/file.c @@ -131,6 +131,7 @@ sftpfs_open_file (vfs_file_handler_t * fh, int flags, mode_t mode, GError ** mce sftpfs_file_handler_t *file = SFTP_FILE_HANDLER (fh); sftpfs_super_t *super = SFTP_SUPER (fh->ino->super); char *name; + const GString *fixfname; (void) mode; mc_return_val_if_error (mcerror, FALSE); @@ -156,13 +157,12 @@ sftpfs_open_file (vfs_file_handler_t * fh, int flags, mode_t mode, GError ** mce else sftp_open_flags = LIBSSH2_FXF_READ; + fixfname = sftpfs_fix_filename (name); + while (TRUE) { - const GString *fixfname; int libssh_errno; - fixfname = sftpfs_fix_filename (name); - file->handle = libssh2_sftp_open_ex (super->sftp_session, fixfname->str, fixfname->len, sftp_open_flags, sftp_open_mode, LIBSSH2_SFTP_OPENFILE); diff --git a/src/vfs/sftpfs/internal.c b/src/vfs/sftpfs/internal.c index 016df81e2..b1576efe2 100644 --- a/src/vfs/sftpfs/internal.c +++ b/src/vfs/sftpfs/internal.c @@ -142,17 +142,16 @@ sftpfs_stat_init (sftpfs_super_t ** super, const vfs_path_element_t ** path_elem const vfs_path_t * vpath, GError ** mcerror, int stat_type, LIBSSH2_SFTP_ATTRIBUTES * attrs) { + const GString *fixfname; int res; if (!sftpfs_op_init (super, path_element, vpath, mcerror)) return -1; + fixfname = sftpfs_fix_filename ((*path_element)->path); + do { - const GString *fixfname; - - fixfname = sftpfs_fix_filename ((*path_element)->path); - res = libssh2_sftp_stat_ex ((*super)->sftp_session, fixfname->str, fixfname->len, stat_type, attrs); if (res >= 0) @@ -346,17 +345,16 @@ sftpfs_readlink (const vfs_path_t * vpath, char *buf, size_t size, GError ** mce { sftpfs_super_t *super = NULL; const vfs_path_element_t *path_element = NULL; + const GString *fixfname; int res; if (!sftpfs_op_init (&super, &path_element, vpath, mcerror)) return -1; + fixfname = sftpfs_fix_filename (path_element->path); + do { - const GString *fixfname; - - fixfname = sftpfs_fix_filename (path_element->path); - res = libssh2_sftp_symlink_ex (super->sftp_session, fixfname->str, fixfname->len, buf, size, LIBSSH2_SFTP_READLINK); @@ -442,6 +440,7 @@ sftpfs_utime (const vfs_path_t * vpath, time_t atime, time_t mtime, GError ** mc sftpfs_super_t *super = NULL; const vfs_path_element_t *path_element = NULL; LIBSSH2_SFTP_ATTRIBUTES attrs; + const GString *fixfname; int res; res = sftpfs_stat_init (&super, &path_element, vpath, mcerror, LIBSSH2_SFTP_LSTAT, &attrs); @@ -452,12 +451,10 @@ sftpfs_utime (const vfs_path_t * vpath, time_t atime, time_t mtime, GError ** mc attrs.atime = atime; attrs.mtime = mtime; + fixfname = sftpfs_fix_filename (path_element->path); + do { - const GString *fixfname; - - fixfname = sftpfs_fix_filename (path_element->path); - res = libssh2_sftp_stat_ex (super->sftp_session, fixfname->str, fixfname->len, LIBSSH2_SFTP_SETSTAT, &attrs); @@ -497,6 +494,7 @@ sftpfs_chmod (const vfs_path_t * vpath, mode_t mode, GError ** mcerror) sftpfs_super_t *super = NULL; const vfs_path_element_t *path_element = NULL; LIBSSH2_SFTP_ATTRIBUTES attrs; + const GString *fixfname; int res; res = sftpfs_stat_init (&super, &path_element, vpath, mcerror, LIBSSH2_SFTP_LSTAT, &attrs); @@ -506,12 +504,10 @@ sftpfs_chmod (const vfs_path_t * vpath, mode_t mode, GError ** mcerror) attrs.flags = LIBSSH2_SFTP_ATTR_PERMISSIONS; attrs.permissions = mode; + fixfname = sftpfs_fix_filename (path_element->path); + do { - const GString *fixfname; - - fixfname = sftpfs_fix_filename (path_element->path); - res = libssh2_sftp_stat_ex (super->sftp_session, fixfname->str, fixfname->len, LIBSSH2_SFTP_SETSTAT, &attrs); @@ -549,17 +545,16 @@ sftpfs_unlink (const vfs_path_t * vpath, GError ** mcerror) { sftpfs_super_t *super = NULL; const vfs_path_element_t *path_element = NULL; + const GString *fixfname; int res; if (!sftpfs_op_init (&super, &path_element, vpath, mcerror)) return -1; + fixfname = sftpfs_fix_filename (path_element->path); + do { - const GString *fixfname; - - fixfname = sftpfs_fix_filename (path_element->path); - res = libssh2_sftp_unlink_ex (super->sftp_session, fixfname->str, fixfname->len); if (res >= 0) break; @@ -591,6 +586,7 @@ sftpfs_rename (const vfs_path_t * vpath1, const vfs_path_t * vpath2, GError ** m const GString *ctmp_path; char *tmp_path; unsigned int tmp_path_len; + const GString *fixfname; int res; if (!sftpfs_op_init (&super, &path_element2, vpath2, mcerror)) @@ -602,12 +598,10 @@ sftpfs_rename (const vfs_path_t * vpath1, const vfs_path_t * vpath2, GError ** m path_element1 = vfs_path_get_by_index (vpath1, -1); + fixfname = sftpfs_fix_filename (path_element1->path); + do { - const GString *fixfname; - - fixfname = sftpfs_fix_filename (path_element1->path); - res = libssh2_sftp_rename_ex (super->sftp_session, fixfname->str, fixfname->len, tmp_path, tmp_path_len, LIBSSH2_SFTP_SYMLINK);