Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unneeded calls to GetWorkingDirectory() in GetListing(path, options) #58

Closed
Charles113 opened this issue Mar 12, 2017 · 2 comments
Closed

Comments

@Charles113
Copy link

Hi,

i just did some profiling because my app was a little bit slower than FileZilla when traversing all directories.
My app has many Calls to GetListing and i noticed GetWorkingDirectory() is called even when not needed.
My profiler said GetWorkingDirectory() uses up 12% of my total execution time.

So i changed the GetListing Function to only call GetWorkingDirectory() when needed

FtpListItem item = null;
List<FtpListItem> lst = new List<FtpListItem>();
List<string> rawlisting = new List<string>();
string listcmd = null;
string pwd = null;
string buf = null;
bool includeSelf = (options & FtpListOption.IncludeSelfAndParent) == FtpListOption.IncludeSelfAndParent;

if (path == null || path.Trim().Length == 0) {
	pwd = GetWorkingDirectory();
	if (pwd != null && pwd.Trim().Length > 0)
		path = pwd;
	else
		path = "./";
} else if (!path.StartsWith("/")) {
	pwd = GetWorkingDirectory();
	if (pwd != null && pwd.Trim().Length > 0)
	{
		if (path.StartsWith("./"))
			path = path.Remove(0, 2);
		path = string.Format("{0}/{1}", pwd, path).GetFtpPath();
	}
}

Maybe this is helpful to someone

Cheers

@robinrodricks
Copy link
Owner

Thank you for this! I will try to absorb your code into the trunk.

@robinrodricks
Copy link
Owner

Your code has been absorbed into the trunk and will be available in the next release!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants