Changeset 462c882


Ignore:
Timestamp:
Sep 18, 2015 10:54:32 PM (4 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
287f94a
Parents:
b8a909c4
Message:

i2psnark: Improve directory listing efficiency (ticket #1079)

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • apps/i2psnark/java/src/org/klomp/snark/Storage.java

    rb8a909c4 r462c882  
    342342   *  @since 0.7.14
    343343   */
     344/****
    344345  public long remaining(int fileIndex) {
    345346      if (fileIndex < 0 || fileIndex >= _torrentFiles.size())
    346347          return -1;
     348      if (complete())
     349          return 0;
    347350      long bytes = 0;
    348351      for (int i = 0; i < _torrentFiles.size(); i++) {
    349352          TorrentFile tf = _torrentFiles.get(i);
    350353          if (i == fileIndex) {
    351               File f = tf.RAFfile;
    352               if (complete())
    353                   return 0;
    354               int psz = piece_size;
    355354              long start = bytes;
    356355              long end = start + tf.length;
    357               int pc = (int) (bytes / psz);
     356              int pc = (int) (bytes / piece_size);
    358357              long rv = 0;
    359358              if (!bitfield.get(pc))
    360                   rv = Math.min(psz - (start % psz), tf.length);
    361               for (int j = pc + 1; (((long)j) * psz) < end && j < pieces; j++) {
     359                  rv = Math.min(piece_size - (start % piece_size), tf.length);
     360              for (int j = pc + 1; (((long)j) * piece_size) < end && j < pieces; j++) {
    362361                  if (!bitfield.get(j)) {
    363                       if (((long)(j+1))*psz < end)
    364                           rv += psz;
     362                      if (((long)(j+1))*piece_size < end)
     363                          rv += piece_size;
    365364                      else
    366                           rv += end - (((long)j) * psz);
     365                          rv += end - (((long)j) * piece_size);
    367366                  }
    368367              }
     
    372371      }
    373372      return -1;
     373  }
     374****/
     375
     376  /**
     377   *  For efficiency, calculate remaining bytes for all files at once
     378   *
     379   *  @return number of bytes remaining for each file, use indexOf() to get index for a file
     380   *  @since 0.9.23
     381   */
     382  public long[] remaining() {
     383      long[] rv = new long[_torrentFiles.size()];
     384      if (complete())
     385          return rv;
     386      long bytes = 0;
     387      for (int i = 0; i < _torrentFiles.size(); i++) {
     388          TorrentFile tf = _torrentFiles.get(i);
     389          long start = bytes;
     390          long end = start + tf.length;
     391          int pc = (int) (bytes / piece_size);
     392          long rvi = 0;
     393          if (!bitfield.get(pc))
     394              rvi = Math.min(piece_size - (start % piece_size), tf.length);
     395          for (int j = pc + 1; (((long)j) * piece_size) < end && j < pieces; j++) {
     396              if (!bitfield.get(j)) {
     397                  if (((long)(j+1))*piece_size < end)
     398                      rvi += piece_size;
     399                  else
     400                      rvi += end - (((long)j) * piece_size);
     401              }
     402          }
     403          rv[i] = rvi;
     404          bytes += tf.length;
     405      }
     406      return rv;
    374407  }
    375408
     
    456489      long pcEnd = -1;
    457490      long fileEnd = _torrentFiles.get(0).length - 1;
    458       int psz = piece_size;
    459491      for (int i = 0; i < rv.length; i++) {
    460           pcEnd += psz;
     492          pcEnd += piece_size;
    461493          int pri = _torrentFiles.get(file).priority;
    462494          while (fileEnd <= pcEnd && file < _torrentFiles.size() - 1) {
  • apps/i2psnark/java/src/org/klomp/snark/web/I2PSnarkServlet.java

    rb8a909c4 r462c882  
    29372937        Storage storage = snark != null ? snark.getStorage() : null;
    29382938        List<Sorters.FileAndIndex> fileList = new ArrayList<Sorters.FileAndIndex>(ls.length);
     2939        // precompute remaining for all files for efficiency
     2940        long[] remainingArray = (storage != null) ? storage.remaining() : null;
    29392941        for (int i = 0; i < ls.length; i++) {
    2940             fileList.add(new Sorters.FileAndIndex(ls[i], storage));
     2942            fileList.add(new Sorters.FileAndIndex(ls[i], storage, remainingArray));
    29412943        }
    29422944
  • apps/i2psnark/java/src/org/klomp/snark/web/Sorters.java

    rb8a909c4 r462c882  
    357357        /**
    358358         *  @param storage may be null
     359         *  @param remaining precomputed, non-null iff storage is non-null
    359360         */
    360         public FileAndIndex(File file, Storage storage) {
     361        public FileAndIndex(File file, Storage storage, long[] remainingArray) {
    361362            this.file = file;
    362363            index = storage != null ? storage.indexOf(file) : -1;
    363364            if (index >= 0) {
    364365                isDirectory = false;
    365                 remaining = storage.remaining(index);
     366                remaining = remainingArray[index];
    366367                priority = storage.getPriority(index);
    367368            } else {
  • history.txt

    rb8a909c4 r462c882  
     12015-09-18 zzz
     2 * EepGet:
     3   - Send Accept-Encoding: gzip even when proxied
     4   - Fix man page (ticket #1631)
     5 * i2psnark:
     6   - Don't display "Tracker Error" if torrent is stopped (ticket #1654)
     7   - Improve directory listing efficiency (ticket #1079)
     8 * i2ptunnel:
     9   - Pass Accept-Encoding header through HTTP client and server proxies,
     10     to allow end-to-end compression
     11   - Don't do transparent response compression if response
     12     Content-Encoding indicates it is already compressed
     13 * Streaming: Move remaining timers from the context to streaming's SimpleTimer2
     14
    1152015-09-17 zzz
    216 * i2psnark:
    317   - Store magnet parameters across restart (ticket #1485)
    4    - Don't delete torrent config file after error on initial startup (ticket #1658)
     18   - Don't delete torrent config file after error on initial startup (tickets #1575, #1658)
    519
    6202015-09-16 zzz
  • router/java/src/net/i2p/router/RouterVersion.java

    rb8a909c4 r462c882  
    1919    public final static String ID = "Monotone";
    2020    public final static String VERSION = CoreVersion.VERSION;
    21     public final static long BUILD = 5;
     21    public final static long BUILD = 6;
    2222
    2323    /** for example "-test" */
Note: See TracChangeset for help on using the changeset viewer.