pjfanning commented on code in PR #1134:
URL: https://github.com/apache/pekko-http/pull/1134#discussion_r3529112450
##########
http/src/main/scala/org/apache/pekko/http/scaladsl/coding/GzipCompressor.scala:
##########
@@ -70,12 +70,26 @@ private[coding] object GzipCompressor {
@InternalApi
private[coding] class GzipDecompressor(
maxBytesPerChunk: Int = Decoder.MaxBytesPerChunkDefault) extends
DeflateDecompressorBase(maxBytesPerChunk) {
+ protected[coding] def createInflater(): Inflater = new Inflater(true)
+
override def createLogic(attr: Attributes) = new ParsingLogic {
- private val inflater = new Inflater(true)
- private val crc32: CRC32 = new CRC32
+ private[this] val inflater = createInflater()
+ private[this] val crc32: CRC32 = new CRC32
+ private[this] var inflaterEnded = false
+
+ private def cleanupInflater(): Unit =
+ if (!inflaterEnded) {
+ inflaterEnded = true
Review Comment:
I prefer the boolean to making `inflater` a var and then checking for nulls.
The nulls approach makes cleanup harder.
```
private def cleanupInflater(): Unit =
if (!inflaterEnded) {
inflaterEnded = true
inflater.end()
}
```
This is not thread-safe.
```
private def cleanupInflater(): Unit =
if (inflater != null) {
inflater.end()
}
```
This is thread-safe but introduces a local variable.
```
private def cleanupInflater(): Unit = {
val localInflater = inflater
if (localInflater != null) {
localInflater.end()
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]