Bug 54299

Summary: more efficient (and shorter) method calls in FTP.makeRemoteDir
Product: Ant Reporter: Adrian Nistor <nistor1>
Component: CoreAssignee: Ant Notifications List <notifications>
Status: RESOLVED FIXED    
Severity: normal CC: jglick, nistor1
Priority: P2 Keywords: PatchAvailable
Version: 1.9.1   
Target Milestone: 1.9.4   
Hardware: PC   
OS: Linux   
Attachments: firstCall.diff
secondCall.diff

Description Adrian Nistor 2012-12-14 20:41:42 UTC
Created attachment 29759 [details]
firstCall.diff

The problem appears in version 1.8.4 and in revision 1421898.  I
attached a one-line patch (firstCall.diff) that fixes it.

In method "FTP.makeRemoteDir", there are two calls to
"dir.indexOf("/") == 0".  These calls should be "dir.startsWith("/")".
The intent of the call is more explicit with "startsWith" than with
"indexOf(..) == 0".  "startsWith" is also more efficient than
"indexOf", because "startsWith" tries to match only the start of the
string, while "indexOf" searches until the first occurrence.

There are many calls to "String.startsWith" in Ant (just like in the
proposed patch), for example, in methods "AntlibDefinition.setURI",
"AntClassLoader.isParentFirst", "ComponentHelper.checkNamespace",
"Execute.getVMSLogicals", "ExecTask.isPath", "Jar.writeIndexLikeList",
"Definer.makeResourceFromURI", "PathTokenizer.nextToken", etc.

I attached a second one-line patch (secondCall.diff) for the second
call.
Comment 1 Adrian Nistor 2012-12-14 20:42:05 UTC
Created attachment 29760 [details]
secondCall.diff
Comment 2 Stefan Bodewig 2014-01-02 14:39:26 UTC
svn revision 1554813