commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject cvs commit: jakarta-commons/net/src/java/org/apache/commons/net/ftp FTPClient.java
Date Tue, 06 Jan 2004 19:02:03 GMT
dfs         2004/01/06 11:02:03

  Modified:    net/src/java/org/apache/commons/net/ftp FTPClient.java
  Log:
  Added caching of the FTPFileEntryParser created in listFiles(String,
  String) to avoid creating a new object every tyime the method is
  called.  This may be regarded as premature optimization, given the
  alleged efficiency of the latest JVMs in creating heap objects and
  collecting garbage.  It is just that file listing is such a common
  operation that it makes sense to avoid repeatedly creating small
  objects when creating one will do..
  
  Revision  Changes    Path
  1.24      +11 -4     jakarta-commons/net/src/java/org/apache/commons/net/ftp/FTPClient.java
  
  Index: FTPClient.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/net/src/java/org/apache/commons/net/ftp/FTPClient.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- FTPClient.java	6 Jan 2004 18:52:56 -0000	1.23
  +++ FTPClient.java	6 Jan 2004 19:02:02 -0000	1.24
  @@ -253,10 +253,14 @@
       private long __restartOffset;
       private FTPFileEntryParserFactory __parserFactory;
   
  -    // __systemName is a cached values that should not be referenced directly
  +    // __systemName is a cached value that should not be referenced directly
       // except when assigned in getSystemName and __initDefaults.
       private String __systemName;
   
  +    // __entryParser is a cached value that should not be referenced directly
  +    // except when assigned in listFiles(String, String) and __initDefaults.
  +    private FTPFileEntryParser __entryParser;
  +
       /***
        * Default FTPClient constructor.  Creates a new FTPClient instance
        * with the data connection mode set to 
  @@ -286,6 +290,7 @@
           __fileTransferMode   = FTP.STREAM_TRANSFER_MODE;
           __restartOffset      = 0;
           __systemName         = null;
  +        __entryParser        = null;
       }
   
       private String __parsePathname(String reply)
  @@ -2054,9 +2059,11 @@
               parserKey = getSystemName();
           }
   
  -        FTPFileEntryParser parser = 
  -          __parserFactory.createFileEntryParser(parserKey);
  -        FTPFileList list = createFileList(pathname, parser);
  +        // We cache the value to avoid creation of a new object every
  +        // time a file listing is generated.
  +        if(__entryParser == null)
  +            __entryParser =  __parserFactory.createFileEntryParser(parserKey);
  +        FTPFileList list = createFileList(pathname, __entryParser);
           return list.getFiles();
       }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message