Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
**Added**
- Add `--summary-only` flag.

**Changed**
- Replace `com.jakewharton.diffuse.io.Size` with `me.saket.bytesize.ByteSize` in the APIs.

**Fixed**
- Significantly improve `.jar` diff performance.

Expand Down
14 changes: 7 additions & 7 deletions formats/api/formats.api
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,19 @@ public final class com/jakewharton/diffuse/format/Apk$Companion {
}

public final class com/jakewharton/diffuse/format/ArchiveFile {
public synthetic fun <init> (Ljava/lang/String;Lcom/jakewharton/diffuse/format/ArchiveFile$Type;JJZLkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Ljava/lang/String;Lcom/jakewharton/diffuse/format/ArchiveFile$Type;Lme/saket/bytesize/ByteSize;Lme/saket/bytesize/ByteSize;Z)V
public final fun component1 ()Ljava/lang/String;
public final fun component2 ()Lcom/jakewharton/diffuse/format/ArchiveFile$Type;
public final fun component3-kab5oJg ()J
public final fun component4-kab5oJg ()J
public final fun component3 ()Lme/saket/bytesize/ByteSize;
public final fun component4 ()Lme/saket/bytesize/ByteSize;
public final fun component5 ()Z
public final fun copy-Ws8QFX4 (Ljava/lang/String;Lcom/jakewharton/diffuse/format/ArchiveFile$Type;JJZ)Lcom/jakewharton/diffuse/format/ArchiveFile;
public static synthetic fun copy-Ws8QFX4$default (Lcom/jakewharton/diffuse/format/ArchiveFile;Ljava/lang/String;Lcom/jakewharton/diffuse/format/ArchiveFile$Type;JJZILjava/lang/Object;)Lcom/jakewharton/diffuse/format/ArchiveFile;
public final fun copy (Ljava/lang/String;Lcom/jakewharton/diffuse/format/ArchiveFile$Type;Lme/saket/bytesize/ByteSize;Lme/saket/bytesize/ByteSize;Z)Lcom/jakewharton/diffuse/format/ArchiveFile;
public static synthetic fun copy$default (Lcom/jakewharton/diffuse/format/ArchiveFile;Ljava/lang/String;Lcom/jakewharton/diffuse/format/ArchiveFile$Type;Lme/saket/bytesize/ByteSize;Lme/saket/bytesize/ByteSize;ZILjava/lang/Object;)Lcom/jakewharton/diffuse/format/ArchiveFile;
public fun equals (Ljava/lang/Object;)Z
public final fun getPath ()Ljava/lang/String;
public final fun getSize-kab5oJg ()J
public final fun getSize ()Lme/saket/bytesize/ByteSize;
public final fun getType ()Lcom/jakewharton/diffuse/format/ArchiveFile$Type;
public final fun getUncompressedSize-kab5oJg ()J
public final fun getUncompressedSize ()Lme/saket/bytesize/ByteSize;
public fun hashCode ()I
public final fun isCompressed ()Z
public fun toString ()Ljava/lang/String;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.jakewharton.diffuse.format

import com.jakewharton.diffuse.format.Arsc as ArscFormat
import com.jakewharton.diffuse.io.Size
import java.util.Locale
import me.saket.bytesize.ByteSize

data class ArchiveFile(
val path: String,
val type: Type,
val size: Size,
val uncompressedSize: Size,
val size: ByteSize,
val uncompressedSize: ByteSize,
val isCompressed: Boolean,
) {
enum class Type {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package com.jakewharton.diffuse.format

import com.jakewharton.diffuse.format.ArchiveFile.Type
import com.jakewharton.diffuse.format.ArchiveFile.Type.Other
import com.jakewharton.diffuse.io.Size
import com.jakewharton.diffuse.io.Zip
import me.saket.bytesize.binaryBytes

class ArchiveFiles internal constructor(private val files: Map<String, ArchiveFile>) :
Map<String, ArchiveFile> by files {
Expand All @@ -26,7 +26,7 @@ class ArchiveFiles internal constructor(private val files: Map<String, ArchiveFi
it.isCompressed,
)
}
.plus("/" to ArchiveFile("/", Other, Size(22), Size.ZERO, false))
.plus("/" to ArchiveFile("/", Other, 22.binaryBytes, 0.binaryBytes, false))
.let(::ArchiveFiles)
}
}
Expand Down
32 changes: 3 additions & 29 deletions io/api/io.api
Original file line number Diff line number Diff line change
Expand Up @@ -44,32 +44,6 @@ public final class com/jakewharton/diffuse/io/PathInput : com/jakewharton/diffus
public fun toZip ()Lcom/jakewharton/diffuse/io/Zip;
}

public final class com/jakewharton/diffuse/io/Size : java/lang/Comparable {
public static final field Companion Lcom/jakewharton/diffuse/io/Size$Companion;
public static final synthetic fun box-impl (J)Lcom/jakewharton/diffuse/io/Size;
public synthetic fun compareTo (Ljava/lang/Object;)I
public fun compareTo-p-hSGm4 (J)I
public static fun compareTo-p-hSGm4 (JJ)I
public static fun constructor-impl (J)J
public fun equals (Ljava/lang/Object;)Z
public static fun equals-impl (JLjava/lang/Object;)Z
public static final fun equals-impl0 (JJ)Z
public static final fun getAbsoluteValue-kab5oJg (J)J
public final fun getBytes ()J
public fun hashCode ()I
public static fun hashCode-impl (J)I
public static final fun minus-2SwpbTA (JJ)J
public static final fun plus-2SwpbTA (JJ)J
public fun toString ()Ljava/lang/String;
public static fun toString-impl (J)Ljava/lang/String;
public static final fun unaryMinus-kab5oJg (J)J
public final synthetic fun unbox-impl ()J
}

public final class com/jakewharton/diffuse/io/Size$Companion {
public final fun getZERO-kab5oJg ()J
}

public final class com/jakewharton/diffuse/io/StringInput : com/jakewharton/diffuse/io/Input {
public fun getName ()Ljava/lang/String;
public fun source ()Lokio/Buffer;
Expand All @@ -95,10 +69,10 @@ public final class com/jakewharton/diffuse/io/Zip$DefaultImpls {

public abstract interface class com/jakewharton/diffuse/io/Zip$Entry {
public abstract fun asInput ()Lcom/jakewharton/diffuse/io/Input;
public abstract fun getCompressedSize-kab5oJg ()J
public abstract fun getCompressedSize ()Lme/saket/bytesize/ByteSize;
public abstract fun getPath ()Ljava/lang/String;
public abstract fun getUncompressedSize-kab5oJg ()J
public abstract fun getZipSize-kab5oJg ()J
public abstract fun getUncompressedSize ()Lme/saket/bytesize/ByteSize;
public abstract fun getZipSize ()Lme/saket/bytesize/ByteSize;
public abstract fun isCompressed ()Z
}

2 changes: 1 addition & 1 deletion io/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apply plugin: 'org.jetbrains.dokka'

dependencies {
api libs.okio
implementation libs.bytesize
api libs.bytesize

testImplementation libs.junit
testImplementation libs.assertk
Expand Down
24 changes: 0 additions & 24 deletions io/src/main/kotlin/com/jakewharton/diffuse/io/Size.kt

This file was deleted.

44 changes: 32 additions & 12 deletions io/src/main/kotlin/com/jakewharton/diffuse/io/Zip.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import java.util.zip.ZipEntry
import java.util.zip.ZipInputStream
import kotlin.io.path.exists
import kotlin.io.path.inputStream
import me.saket.bytesize.BinaryByteSize
import me.saket.bytesize.ByteSize
import okio.ByteString
import okio.utf8Size

Expand Down Expand Up @@ -47,13 +49,13 @@ interface Zip : Closeable {
val path: String

/** The uncompressed size of the entry contents */
val uncompressedSize: Size
val uncompressedSize: ByteSize

/** The compressed size of the entry contents. */
val compressedSize: Size
val compressedSize: ByteSize

/** The impact on the overall zip size. This is [compressedSize] plus metadata. */
val zipSize: Size
val zipSize: ByteSize

/** Returns true if the entry is compressed using any method other than 'store'. */
val isCompressed: Boolean
Expand All @@ -64,15 +66,27 @@ interface Zip : Closeable {

private fun <T : Zip.Entry> ZipInputStream.mapEntries(
entryFactory:
(name: String, size: Size, compressedSize: Size, zipSize: Size, isCompressed: Boolean) -> T
(
name: String,
size: ByteSize,
compressedSize: ByteSize,
zipSize: ByteSize,
isCompressed: Boolean,
) -> T
): List<T> {
return entries().map { it.toZipEntry(this, entryFactory) }.toList()
}

private fun <T : Zip.Entry> ZipEntry.toZipEntry(
zipStream: ZipInputStream,
entryFactory:
(name: String, size: Size, compressedSize: Size, zipSize: Size, isCompressed: Boolean) -> T,
(
name: String,
size: ByteSize,
compressedSize: ByteSize,
zipSize: ByteSize,
isCompressed: Boolean,
) -> T,
): T {
val isCompressed = method != ZipEntry.STORED
val nameSize = name.utf8Size()
Expand Down Expand Up @@ -113,7 +127,13 @@ private fun <T : Zip.Entry> ZipEntry.toZipEntry(
extraSize +
commentSize

return entryFactory(name, Size(size), Size(compressedSize), Size(zipSize), isCompressed)
return entryFactory(
name,
BinaryByteSize(size),
BinaryByteSize(compressedSize),
BinaryByteSize(zipSize),
isCompressed,
)
}

internal fun Path.toZip(): Zip {
Expand All @@ -133,9 +153,9 @@ internal class PathZip(fs: FileSystem, override val entries: List<Zip.Entry>) :
class Entry(
private val root: Path,
override val path: String,
override val uncompressedSize: Size,
override val compressedSize: Size,
override val zipSize: Size,
override val uncompressedSize: ByteSize,
override val compressedSize: ByteSize,
override val zipSize: ByteSize,
override val isCompressed: Boolean,
) : Zip.Entry {
override fun asInput(): Input {
Expand All @@ -160,9 +180,9 @@ internal class BytesZip(override val entries: List<Zip.Entry>) : Zip {
class Entry(
private val bytes: ByteString,
override val path: String,
override val uncompressedSize: Size,
override val compressedSize: Size,
override val zipSize: Size,
override val uncompressedSize: ByteSize,
override val compressedSize: ByteSize,
override val zipSize: ByteSize,
override val isCompressed: Boolean,
) : Zip.Entry {
override fun asInput(): Input {
Expand Down
20 changes: 0 additions & 20 deletions io/src/test/kotlin/com/jakewharton/diffuse/io/SizeTest.kt

This file was deleted.

5 changes: 3 additions & 2 deletions io/src/test/kotlin/com/jakewharton/diffuse/io/ZipTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.jakewharton.diffuse.io
import assertk.assertThat
import assertk.assertions.isEqualTo
import com.jakewharton.diffuse.testing.decodeHexWithWhitespace
import me.saket.bytesize.binaryBytes
import org.junit.Test

class ZipTest {
Expand All @@ -23,7 +24,7 @@ class ZipTest {
.toZip()
val entry = zip.entries.single()

assertThat(entry.compressedSize).isEqualTo(Size(7))
assertThat(entry.uncompressedSize).isEqualTo(Size(5))
assertThat(entry.compressedSize).isEqualTo(7.binaryBytes)
assertThat(entry.uncompressedSize).isEqualTo(5.binaryBytes)
Comment on lines +27 to +28
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import com.jakewharton.diffuse.diff.ArchiveFilesDiff.Change
import com.jakewharton.diffuse.diffuseTable
import com.jakewharton.diffuse.format.ArchiveFile.Type
import com.jakewharton.diffuse.format.ArchiveFiles
import com.jakewharton.diffuse.io.Size
import com.jakewharton.diffuse.report.toDiffString
import com.jakewharton.picnic.TableSectionDsl
import com.jakewharton.picnic.TextAlignment.BottomCenter
import com.jakewharton.picnic.TextAlignment.BottomLeft
import com.jakewharton.picnic.TextAlignment.MiddleCenter
import com.jakewharton.picnic.TextAlignment.MiddleRight
import com.jakewharton.picnic.renderText
import me.saket.bytesize.ByteSize
import me.saket.bytesize.binaryBytes

internal class ArchiveFilesDiff(
val oldFiles: ArchiveFiles,
Expand All @@ -20,10 +21,10 @@ internal class ArchiveFilesDiff(
) {
data class Change(
val path: String,
val size: Size,
val sizeDiff: Size,
val uncompressedSize: Size,
val uncompressedSizeDiff: Size,
val size: ByteSize,
val sizeDiff: ByteSize,
val uncompressedSize: ByteSize,
val uncompressedSizeDiff: ByteSize,
val type: Type,
) {
enum class Type {
Expand Down Expand Up @@ -54,9 +55,9 @@ internal class ArchiveFilesDiff(
if (path !in newFiles) {
Change(
path,
Size.ZERO,
0.binaryBytes,
-oldFile.size,
Size.ZERO,
0.binaryBytes,
-oldFile.uncompressedSize,
Change.Type.Removed,
)
Expand Down Expand Up @@ -130,13 +131,13 @@ internal fun ArchiveFilesDiff.toSummaryTable(
fun TableSectionDsl.addApkRow(name: String, type: Type? = null) {
val old = if (type != null) oldFiles.filterValues { it.type == type } else oldFiles
val new = if (type != null) newFiles.filterValues { it.type == type } else newFiles
val oldSize = old.values.fold(Size.ZERO) { acc, file -> acc + file.size }
val newSize = new.values.fold(Size.ZERO) { acc, file -> acc + file.size }
val oldSize = old.values.fold(0.binaryBytes) { acc, file -> acc + file.size }
val newSize = new.values.fold(0.binaryBytes) { acc, file -> acc + file.size }
val oldUncompressedSize =
old.values.fold(Size.ZERO) { acc, file -> acc + file.uncompressedSize }
old.values.fold(0.binaryBytes) { acc, file -> acc + file.uncompressedSize }
val newUncompressedSize =
new.values.fold(Size.ZERO) { acc, file -> acc + file.uncompressedSize }
if (oldSize != Size.ZERO || newSize != Size.ZERO || type !in skipIfEmptyTypes) {
new.values.fold(0.binaryBytes) { acc, file -> acc + file.uncompressedSize }
if (oldSize != 0.binaryBytes || newSize != 0.binaryBytes || type !in skipIfEmptyTypes) {
val uncompressedDiff = (newUncompressedSize - oldUncompressedSize).toDiffString()
if (includeCompressed) {
row(
Expand Down Expand Up @@ -200,15 +201,15 @@ internal fun ArchiveFilesDiff.toDetailReport() = buildString {
footer {
row {
if (includeCompressed) {
val totalSize = changes.fold(Size.ZERO) { acc, change -> acc + change.size }
val totalDiff = changes.fold(Size.ZERO) { acc, change -> acc + change.sizeDiff }
val totalSize = changes.fold(0.binaryBytes) { acc, change -> acc + change.size }
val totalDiff = changes.fold(0.binaryBytes) { acc, change -> acc + change.sizeDiff }
cell(totalSize) { alignment = MiddleRight }
cell(totalDiff.toDiffString()) { alignment = MiddleRight }
}
val totalUncompressedSize =
changes.fold(Size.ZERO) { acc, change -> acc + change.uncompressedSize }
changes.fold(0.binaryBytes) { acc, change -> acc + change.uncompressedSize }
val totalUncompressedDiff =
changes.fold(Size.ZERO) { acc, change -> acc + change.uncompressedSizeDiff }
changes.fold(0.binaryBytes) { acc, change -> acc + change.uncompressedSizeDiff }
cell(totalUncompressedSize) { alignment = MiddleRight }
cell(totalUncompressedDiff.toDiffString()) { alignment = MiddleRight }
cell("(total)")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.jakewharton.diffuse.diff

import kotlin.math.absoluteValue
import me.saket.bytesize.BinaryByteSize
import me.saket.bytesize.ByteSize
import me.saket.bytesize.DecimalBitSize
import me.saket.bytesize.DecimalByteSize

/** TODO: https://github.com/saket/byte-size/pull/21 */
internal val ByteSize.absoluteValue: ByteSize
get() =
when (this) {
is DecimalBitSize -> DecimalBitSize(inWholeBits.absoluteValue)
is BinaryByteSize -> BinaryByteSize(inWholeBytes.absoluteValue)
is DecimalByteSize -> DecimalByteSize(inWholeBytes.absoluteValue)
}

/** TODO: https://github.com/saket/byte-size/pull/20 */
@Suppress("NOTHING_TO_INLINE")
internal inline operator fun ByteSize.unaryMinus(): ByteSize =
when (this) {
is DecimalBitSize -> DecimalBitSize(-inWholeBits)
is BinaryByteSize -> BinaryByteSize(-inWholeBytes)
is DecimalByteSize -> DecimalByteSize(-inWholeBytes)
}
Loading