Skip to content

Commit 08ec63f

Browse files
committed
Replace Size with BinaryByteSize
1 parent a36b7b5 commit 08ec63f

13 files changed

Lines changed: 87 additions & 117 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
**Added**
77
- Add `--summary-only` flag.
88

9+
**Changed**
10+
- Replace `com.jakewharton.diffuse.io.Size` with `me.saket.bytesize.BinaryByteSize` in the APIs.
11+
912
**Fixed**
1013
- Significantly improve `.jar` diff performance.
1114

formats/api/formats.api

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,16 @@ public final class com/jakewharton/diffuse/format/ArchiveFile {
100100
public synthetic fun <init> (Ljava/lang/String;Lcom/jakewharton/diffuse/format/ArchiveFile$Type;JJZLkotlin/jvm/internal/DefaultConstructorMarker;)V
101101
public final fun component1 ()Ljava/lang/String;
102102
public final fun component2 ()Lcom/jakewharton/diffuse/format/ArchiveFile$Type;
103-
public final fun component3-kab5oJg ()J
104-
public final fun component4-kab5oJg ()J
103+
public final fun component3-7zWN8Bo ()J
104+
public final fun component4-7zWN8Bo ()J
105105
public final fun component5 ()Z
106-
public final fun copy-Ws8QFX4 (Ljava/lang/String;Lcom/jakewharton/diffuse/format/ArchiveFile$Type;JJZ)Lcom/jakewharton/diffuse/format/ArchiveFile;
107-
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;
106+
public final fun copy-5A1BZgA (Ljava/lang/String;Lcom/jakewharton/diffuse/format/ArchiveFile$Type;JJZ)Lcom/jakewharton/diffuse/format/ArchiveFile;
107+
public static synthetic fun copy-5A1BZgA$default (Lcom/jakewharton/diffuse/format/ArchiveFile;Ljava/lang/String;Lcom/jakewharton/diffuse/format/ArchiveFile$Type;JJZILjava/lang/Object;)Lcom/jakewharton/diffuse/format/ArchiveFile;
108108
public fun equals (Ljava/lang/Object;)Z
109109
public final fun getPath ()Ljava/lang/String;
110-
public final fun getSize-kab5oJg ()J
110+
public final fun getSize-7zWN8Bo ()J
111111
public final fun getType ()Lcom/jakewharton/diffuse/format/ArchiveFile$Type;
112-
public final fun getUncompressedSize-kab5oJg ()J
112+
public final fun getUncompressedSize-7zWN8Bo ()J
113113
public fun hashCode ()I
114114
public final fun isCompressed ()Z
115115
public fun toString ()Ljava/lang/String;

formats/src/main/kotlin/com/jakewharton/diffuse/format/ArchiveFile.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package com.jakewharton.diffuse.format
22

33
import com.jakewharton.diffuse.format.Arsc as ArscFormat
4-
import com.jakewharton.diffuse.io.Size
54
import java.util.Locale
5+
import me.saket.bytesize.BinaryByteSize
66

77
data class ArchiveFile(
88
val path: String,
99
val type: Type,
10-
val size: Size,
11-
val uncompressedSize: Size,
10+
val size: BinaryByteSize,
11+
val uncompressedSize: BinaryByteSize,
1212
val isCompressed: Boolean,
1313
) {
1414
enum class Type {

formats/src/main/kotlin/com/jakewharton/diffuse/format/ArchiveFiles.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package com.jakewharton.diffuse.format
22

33
import com.jakewharton.diffuse.format.ArchiveFile.Type
44
import com.jakewharton.diffuse.format.ArchiveFile.Type.Other
5-
import com.jakewharton.diffuse.io.Size
65
import com.jakewharton.diffuse.io.Zip
6+
import me.saket.bytesize.binaryBytes
77

88
class ArchiveFiles internal constructor(private val files: Map<String, ArchiveFile>) :
99
Map<String, ArchiveFile> by files {
@@ -26,7 +26,7 @@ class ArchiveFiles internal constructor(private val files: Map<String, ArchiveFi
2626
it.isCompressed,
2727
)
2828
}
29-
.plus("/" to ArchiveFile("/", Other, Size(22), Size.ZERO, false))
29+
.plus("/" to ArchiveFile("/", Other, 22.binaryBytes, 0.binaryBytes, false))
3030
.let(::ArchiveFiles)
3131
}
3232
}

io/api/io.api

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -44,30 +44,9 @@ public final class com/jakewharton/diffuse/io/PathInput : com/jakewharton/diffus
4444
public fun toZip ()Lcom/jakewharton/diffuse/io/Zip;
4545
}
4646

47-
public final class com/jakewharton/diffuse/io/Size : java/lang/Comparable {
48-
public static final field Companion Lcom/jakewharton/diffuse/io/Size$Companion;
49-
public static final synthetic fun box-impl (J)Lcom/jakewharton/diffuse/io/Size;
50-
public synthetic fun compareTo (Ljava/lang/Object;)I
51-
public fun compareTo-p-hSGm4 (J)I
52-
public static fun compareTo-p-hSGm4 (JJ)I
53-
public static fun constructor-impl (J)J
54-
public fun equals (Ljava/lang/Object;)Z
55-
public static fun equals-impl (JLjava/lang/Object;)Z
56-
public static final fun equals-impl0 (JJ)Z
57-
public static final fun getAbsoluteValue-kab5oJg (J)J
58-
public final fun getBytes ()J
59-
public fun hashCode ()I
60-
public static fun hashCode-impl (J)I
61-
public static final fun minus-2SwpbTA (JJ)J
62-
public static final fun plus-2SwpbTA (JJ)J
63-
public fun toString ()Ljava/lang/String;
64-
public static fun toString-impl (J)Ljava/lang/String;
65-
public static final fun unaryMinus-kab5oJg (J)J
66-
public final synthetic fun unbox-impl ()J
67-
}
68-
69-
public final class com/jakewharton/diffuse/io/Size$Companion {
70-
public final fun getZERO-kab5oJg ()J
47+
public final class com/jakewharton/diffuse/io/SizeKt {
48+
public static final fun getAbsoluteValue-bso2BsE (J)J
49+
public static final fun unaryMinus-bso2BsE (J)J
7150
}
7251

7352
public final class com/jakewharton/diffuse/io/StringInput : com/jakewharton/diffuse/io/Input {
@@ -95,10 +74,10 @@ public final class com/jakewharton/diffuse/io/Zip$DefaultImpls {
9574

9675
public abstract interface class com/jakewharton/diffuse/io/Zip$Entry {
9776
public abstract fun asInput ()Lcom/jakewharton/diffuse/io/Input;
98-
public abstract fun getCompressedSize-kab5oJg ()J
77+
public abstract fun getCompressedSize-7zWN8Bo ()J
9978
public abstract fun getPath ()Ljava/lang/String;
100-
public abstract fun getUncompressedSize-kab5oJg ()J
101-
public abstract fun getZipSize-kab5oJg ()J
79+
public abstract fun getUncompressedSize-7zWN8Bo ()J
80+
public abstract fun getZipSize-7zWN8Bo ()J
10281
public abstract fun isCompressed ()Z
10382
}
10483

io/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ apply plugin: 'org.jetbrains.dokka'
44

55
dependencies {
66
api libs.okio
7-
implementation libs.bytesize
7+
api libs.bytesize
88

99
testImplementation libs.junit
1010
testImplementation libs.assertk
Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,9 @@
11
package com.jakewharton.diffuse.io
22

33
import kotlin.math.absoluteValue
4-
import me.saket.bytesize.binaryBytes
4+
import me.saket.bytesize.BinaryByteSize
55

6-
@JvmInline
7-
value class Size(val bytes: Long) : Comparable<Size> {
8-
override fun toString(): String = bytes.binaryBytes.toString()
6+
val BinaryByteSize.absoluteValue: BinaryByteSize
7+
get() = BinaryByteSize(inWholeBytes.absoluteValue)
98

10-
override fun compareTo(other: Size) = bytes.compareTo(other.bytes)
11-
12-
operator fun plus(other: Size) = Size(bytes + other.bytes)
13-
14-
operator fun minus(other: Size) = Size(bytes - other.bytes)
15-
16-
operator fun unaryMinus() = Size(-bytes)
17-
18-
val absoluteValue
19-
get() = Size(bytes.absoluteValue)
20-
21-
companion object {
22-
val ZERO = Size(0)
23-
}
24-
}
9+
operator fun BinaryByteSize.unaryMinus() = BinaryByteSize(-inWholeBytes)

io/src/main/kotlin/com/jakewharton/diffuse/io/Zip.kt

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import java.util.zip.ZipEntry
99
import java.util.zip.ZipInputStream
1010
import kotlin.io.path.exists
1111
import kotlin.io.path.inputStream
12+
import me.saket.bytesize.BinaryByteSize
1213
import okio.ByteString
1314
import okio.utf8Size
1415

@@ -47,13 +48,13 @@ interface Zip : Closeable {
4748
val path: String
4849

4950
/** The uncompressed size of the entry contents */
50-
val uncompressedSize: Size
51+
val uncompressedSize: BinaryByteSize
5152

5253
/** The compressed size of the entry contents. */
53-
val compressedSize: Size
54+
val compressedSize: BinaryByteSize
5455

5556
/** The impact on the overall zip size. This is [compressedSize] plus metadata. */
56-
val zipSize: Size
57+
val zipSize: BinaryByteSize
5758

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

6566
private fun <T : Zip.Entry> ZipInputStream.mapEntries(
6667
entryFactory:
67-
(name: String, size: Size, compressedSize: Size, zipSize: Size, isCompressed: Boolean) -> T
68+
(
69+
name: String,
70+
size: BinaryByteSize,
71+
compressedSize: BinaryByteSize,
72+
zipSize: BinaryByteSize,
73+
isCompressed: Boolean,
74+
) -> T
6875
): List<T> {
6976
return entries().map { it.toZipEntry(this, entryFactory) }.toList()
7077
}
7178

7279
private fun <T : Zip.Entry> ZipEntry.toZipEntry(
7380
zipStream: ZipInputStream,
7481
entryFactory:
75-
(name: String, size: Size, compressedSize: Size, zipSize: Size, isCompressed: Boolean) -> T,
82+
(
83+
name: String,
84+
size: BinaryByteSize,
85+
compressedSize: BinaryByteSize,
86+
zipSize: BinaryByteSize,
87+
isCompressed: Boolean,
88+
) -> T,
7689
): T {
7790
val isCompressed = method != ZipEntry.STORED
7891
val nameSize = name.utf8Size()
@@ -113,7 +126,13 @@ private fun <T : Zip.Entry> ZipEntry.toZipEntry(
113126
extraSize +
114127
commentSize
115128

116-
return entryFactory(name, Size(size), Size(compressedSize), Size(zipSize), isCompressed)
129+
return entryFactory(
130+
name,
131+
BinaryByteSize(size),
132+
BinaryByteSize(compressedSize),
133+
BinaryByteSize(zipSize),
134+
isCompressed,
135+
)
117136
}
118137

119138
internal fun Path.toZip(): Zip {
@@ -133,9 +152,9 @@ internal class PathZip(fs: FileSystem, override val entries: List<Zip.Entry>) :
133152
class Entry(
134153
private val root: Path,
135154
override val path: String,
136-
override val uncompressedSize: Size,
137-
override val compressedSize: Size,
138-
override val zipSize: Size,
155+
override val uncompressedSize: BinaryByteSize,
156+
override val compressedSize: BinaryByteSize,
157+
override val zipSize: BinaryByteSize,
139158
override val isCompressed: Boolean,
140159
) : Zip.Entry {
141160
override fun asInput(): Input {
@@ -160,9 +179,9 @@ internal class BytesZip(override val entries: List<Zip.Entry>) : Zip {
160179
class Entry(
161180
private val bytes: ByteString,
162181
override val path: String,
163-
override val uncompressedSize: Size,
164-
override val compressedSize: Size,
165-
override val zipSize: Size,
182+
override val uncompressedSize: BinaryByteSize,
183+
override val compressedSize: BinaryByteSize,
184+
override val zipSize: BinaryByteSize,
166185
override val isCompressed: Boolean,
167186
) : Zip.Entry {
168187
override fun asInput(): Input {

io/src/test/kotlin/com/jakewharton/diffuse/io/SizeTest.kt

Lines changed: 0 additions & 20 deletions
This file was deleted.

io/src/test/kotlin/com/jakewharton/diffuse/io/ZipTest.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.jakewharton.diffuse.io
33
import assertk.assertThat
44
import assertk.assertions.isEqualTo
55
import com.jakewharton.diffuse.testing.decodeHexWithWhitespace
6+
import me.saket.bytesize.binaryBytes
67
import org.junit.Test
78

89
class ZipTest {
@@ -23,7 +24,7 @@ class ZipTest {
2324
.toZip()
2425
val entry = zip.entries.single()
2526

26-
assertThat(entry.compressedSize).isEqualTo(Size(7))
27-
assertThat(entry.uncompressedSize).isEqualTo(Size(5))
27+
assertThat(entry.compressedSize).isEqualTo(7.binaryBytes)
28+
assertThat(entry.uncompressedSize).isEqualTo(5.binaryBytes)
2829
}
2930
}

0 commit comments

Comments
 (0)