On Sunday 22 June 2008 09:44, Florent Daigni?re wrote:
> * toad at freenetproject.org <toad at freenetproject.org> [2008-06-21 
> 14:38:38]:
> 
> > Author: toad
> > Date: 2008-06-21 14:38:38 +0000 (Sat, 21 Jun 2008)
> > New Revision: 20573
> > 
> > Added:
> >    
branches/db4o/freenet/src/freenet/support/io/BucketChainBucketFactory.java
> > Modified:
> >    branches/db4o/freenet/src/freenet/client/async/InsertCompressor.java
> >    branches/db4o/freenet/src/freenet/client/async/SplitFileInserter.java
> >    branches/db4o/freenet/src/freenet/support/io/BucketChainBucket.java
> >    branches/db4o/freenet/src/freenet/support/io/BucketTools.java
> > Log:
> > Write compressed data directly into a chain of buckets.
> > Saves copying, disk space, and time later on. (Currently this time is on 
the database thread, because it's in the SplitFileFetcher constructor...).
> > BACKPORT.
> > 
> > Modified: branches/db4o/freenet/src/freenet/support/io/BucketTools.java
> > ===================================================================
> > --- branches/db4o/freenet/src/freenet/support/io/BucketTools.java   
2008-06-21 14:23:52 UTC (rev 20572)
> > +++ branches/db4o/freenet/src/freenet/support/io/BucketTools.java   
2008-06-21 14:38:38 UTC (rev 20573)
> > @@ -334,13 +334,27 @@
> >      * and the data written to them.
> >      * 
> >      * Note that this method will allocate a buffer of size splitSize.
> > +    * @param freeData 
> >      * @throws IOException If there is an error creating buckets, reading 
from
> >      * the provided bucket, or writing to created buckets.
> >      */
> > -   public static Bucket[] split(Bucket origData, int splitSize, 
BucketFactory bf) throws IOException {
> > +   public static Bucket[] split(Bucket origData, int splitSize, 
BucketFactory bf, boolean freeData) throws IOException {
> >             if(origData instanceof FileBucket) {
> > +                   if(freeData) {
> > +                           Logger.error(BucketTools.class, "Asked to free 
> > data when splitting a 
FileBucket ?!?!? Not freeing as this would clobber the split result...");
> > +                   }
> >                     return ((FileBucket)origData).split(splitSize);
> >             }
> > +           if(origData instanceof BucketChainBucket) {
> > +                   BucketChainBucket data = (BucketChainBucket)origData;
> > +                   if(data.bucketSize == splitSize) {
> > +                           if(freeData)
> > +                                   data.clear();
> > +                           return data.getBuckets();
> > +                   } else {
> > +                           Logger.error(BucketTools.class, "Incompatible 
> > split size splitting a 
BucketChainBucket: his split size is "+data.bucketSize+" but mine 
is "+splitSize+" - we will copy the data, but this suggests a bug", new 
Exception("debug"));
> > +                   }
> > +           }
> >             long length = origData.size();
> >             if(length > ((long)Integer.MAX_VALUE) * splitSize)
> >                     throw new IllegalArgumentException("Way too big!: 
> > "+length+" 
for "+splitSize);
> > @@ -374,6 +388,8 @@
> >                     else
> >                             is.close();
> >             }
> > +           if(freeData)
> > +                   origData.free();
> >             return buckets;
> >     }
> 
> Is there a reason why we don't do the origData.free() in the finally
> block above ?
> 
Yes, we don't want to free it if we don't return anything because we throw!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: 
<https://emu.freenetproject.org/pipermail/devl/attachments/20080624/73fdc1d9/attachment.pgp>

Reply via email to