hadoop-hdfs-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "BELUGA BEHR (JIRA)" <j...@apache.org>
Subject [jira] [Created] (HDFS-11931) FileSystem Simplify / Optimize listStatus Method
Date Mon, 05 Jun 2017 15:53:04 GMT
BELUGA BEHR created HDFS-11931:

             Summary: FileSystem Simplify / Optimize listStatus Method
                 Key: HDFS-11931
                 URL: https://issues.apache.org/jira/browse/HDFS-11931
             Project: Hadoop HDFS
          Issue Type: Improvement
          Components: fs
    Affects Versions: 3.0.0-alpha3, 2.7.3
            Reporter: BELUGA BEHR
            Priority: Minor

{code:title=org.apache.hadoop.fs.FileSystem.listStatus(ArrayList<FileStatus>, Path,
   * Filter files/directories in the given path using the user-supplied path
   * filter. Results are added to the given array <code>results</code>.
  private void listStatus(ArrayList<FileStatus> results, Path f,
      PathFilter filter) throws FileNotFoundException, IOException {
    FileStatus listing[] = listStatus(f);
    if (listing == null) {
      throw new IOException("Error accessing " + f);

    for (int i = 0; i < listing.length; i++) {
      if (filter.accept(listing[i].getPath())) {

{code:title=org.apache.hadoop.fs.FileSystem.listStatus(Path, PathFilter)}
  public FileStatus[] listStatus(Path f, PathFilter filter) 
                                   throws FileNotFoundException, IOException {
    ArrayList<FileStatus> results = new ArrayList<FileStatus>();
    listStatus(results, f, filter);
    return results.toArray(new FileStatus[results.size()]);

We can be smarter about this:

# Use enhanced for-loops
# Optimize for the case where there are zero files in a directory, save on object instantiation
# More encapsulated design

This message was sent by Atlassian JIRA

To unsubscribe, e-mail: hdfs-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: hdfs-issues-help@hadoop.apache.org

View raw message