You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-dev@hadoop.apache.org by "BELUGA BEHR (JIRA)" <ji...@apache.org> on 2017/06/01 21:43:04 UTC

[jira] [Created] (HADOOP-14477) FileSystem Simplify / Optimize listStatus Method

BELUGA BEHR created HADOOP-14477:
------------------------------------

             Summary: FileSystem Simplify / Optimize listStatus Method
                 Key: HADOOP-14477
                 URL: https://issues.apache.org/jira/browse/HADOOP-14477
             Project: Hadoop Common
          Issue Type: Improvement
    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, PathFilter)}
  /*
   * 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())) {
        results.add(listing[i]);
      }
    }
  }
{code}

{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()]);
  }
{code}

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



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

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