Author: toad
Date: 2007-02-03 16:28:23 +0000 (Sat, 03 Feb 2007)
New Revision: 11661
Modified:
trunk/freenet/src/freenet/keys/ClientCHKBlock.java
trunk/freenet/src/freenet/keys/ClientSSKBlock.java
trunk/freenet/src/freenet/keys/Key.java
Log:
More memory optimisations
Modified: trunk/freenet/src/freenet/keys/ClientCHKBlock.java
===================================================================
--- trunk/freenet/src/freenet/keys/ClientCHKBlock.java 2007-02-03 16:05:56 UTC
(rev 11660)
+++ trunk/freenet/src/freenet/keys/ClientCHKBlock.java 2007-02-03 16:28:23 UTC
(rev 11661)
@@ -114,10 +114,7 @@
int size = ((hbuf[32] & 0xff) << 8) + (hbuf[33] & 0xff);
if((size > 32768) || (size < 0))
throw new CHKDecodeException("Invalid size: "+size);
- byte[] output = new byte[size];
- // No particular reason to check the padding, is there?
- System.arraycopy(dbuf, 0, output, 0, size);
- return Key.decompress(dontCompress ? false : key.isCompressed(),
output, bf, Math.min(maxLength, MAX_LENGTH_BEFORE_COMPRESSION),
key.compressionAlgorithm, false);
+ return Key.decompress(dontCompress ? false : key.isCompressed(), dbuf,
size, bf, Math.min(maxLength, MAX_LENGTH_BEFORE_COMPRESSION),
key.compressionAlgorithm, false);
}
/**
Modified: trunk/freenet/src/freenet/keys/ClientSSKBlock.java
===================================================================
--- trunk/freenet/src/freenet/keys/ClientSSKBlock.java 2007-02-03 16:05:56 UTC
(rev 11660)
+++ trunk/freenet/src/freenet/keys/ClientSSKBlock.java 2007-02-03 16:28:23 UTC
(rev 11661)
@@ -79,11 +79,6 @@
throw new SSKDecodeException("Data length:
"+dataLength+" but data.length="+data.length);
}
- if(dataLength != data.length) {
- byte[] realDataOutput = new byte[dataLength];
- System.arraycopy(dataOutput, 0, realDataOutput, 0,
dataLength);
- dataOutput = realDataOutput;
- }
compressionAlgorithm =
(short)(((decryptedHeaders[DATA_DECRYPT_KEY_LENGTH+2] & 0xff) << 8) +
(decryptedHeaders[DATA_DECRYPT_KEY_LENGTH+3] & 0xff));
decoded = true;
@@ -91,7 +86,7 @@
return BucketTools.makeImmutableBucket(factory, dataOutput);
}
- Bucket b = Key.decompress(compressionAlgorithm >= 0, dataOutput,
factory, Math.min(MAX_DECOMPRESSED_DATA_LENGTH, maxLength),
compressionAlgorithm, true);
+ Bucket b = Key.decompress(compressionAlgorithm >= 0, dataOutput,
dataLength, factory, Math.min(MAX_DECOMPRESSED_DATA_LENGTH, maxLength),
compressionAlgorithm, true);
return b;
}
Modified: trunk/freenet/src/freenet/keys/Key.java
===================================================================
--- trunk/freenet/src/freenet/keys/Key.java 2007-02-03 16:05:56 UTC (rev
11660)
+++ trunk/freenet/src/freenet/keys/Key.java 2007-02-03 16:28:23 UTC (rev
11661)
@@ -101,7 +101,7 @@
return this.hash == o.hashCode();
}
- static Bucket decompress(boolean isCompressed, byte[] output,
BucketFactory bf, int maxLength, short compressionAlgorithm, boolean
shortLength) throws CHKDecodeException, IOException {
+ static Bucket decompress(boolean isCompressed, byte[] output, int
outputLength, BucketFactory bf, int maxLength, short compressionAlgorithm,
boolean shortLength) throws CHKDecodeException, IOException {
if(isCompressed) {
if(Logger.shouldLog(Logger.MINOR, Key.class))
Logger.minor(Key.class, "Decompressing
"+output.length+" bytes in decode with codec "+compressionAlgorithm);
@@ -117,7 +117,7 @@
if(len > maxLength)
throw new CHKDecodeException("Invalid precompressed size:
"+len);
Compressor decompressor =
Compressor.getCompressionAlgorithmByMetadataID(compressionAlgorithm);
- Bucket inputBucket = new SimpleReadOnlyArrayBucket(output,
shortLength?2:4, output.length-(shortLength?2:4));
+ Bucket inputBucket = new SimpleReadOnlyArrayBucket(output,
shortLength?2:4, outputLength-(shortLength?2:4));
try {
return decompressor.decompress(inputBucket, bf,
maxLength, -1, null);
} catch (CompressionOutputSizeException e) {