Reduce use of ByteBuf{Input,Output}Stream in Js5Compression

Probably slightly more efficient.

Signed-off-by: Graham <gpe@openrs2.dev>
Graham 4 years ago
parent 8887b0a1e9
commit ce97775663
  1. 8
      cache/src/main/java/dev/openrs2/cache/Js5Compression.kt

@ -33,9 +33,7 @@ object Js5Compression {
val start = output.writerIndex() val start = output.writerIndex()
type.createOutputStream(ByteBufOutputStream(output)).use { outputStream -> type.createOutputStream(ByteBufOutputStream(output)).use { outputStream ->
ByteBufInputStream(input).use { inputStream -> input.readBytes(outputStream, input.readableBytes())
inputStream.copyTo(outputStream)
}
} }
val len = output.writerIndex() - start val len = output.writerIndex() - start
@ -103,9 +101,7 @@ object Js5Compression {
plaintext.alloc().buffer(uncompressedLen, uncompressedLen).use { output -> plaintext.alloc().buffer(uncompressedLen, uncompressedLen).use { output ->
type.createInputStream(ByteBufInputStream(plaintext, len), uncompressedLen).use { inputStream -> type.createInputStream(ByteBufInputStream(plaintext, len), uncompressedLen).use { inputStream ->
ByteBufOutputStream(output).use { outputStream -> output.writeBytes(inputStream, output.writableBytes())
inputStream.copyTo(outputStream)
}
} }
return output.retain() return output.retain()

Loading…
Cancel
Save