Convert receiver to parameter

This commit is contained in:
Karlatemp 2020-09-20 14:10:08 +08:00
parent 46ec2460b3
commit 44598aa1fa
No known key found for this signature in database
GPG Key ID: 21FBDDF664FF06F8
2 changed files with 6 additions and 6 deletions

View File

@ -120,23 +120,23 @@ internal object SemVersionInternal {
}
@JvmStatic
fun SemVersion.compareInternal(other: SemVersion): Int {
fun compareInternal(source: SemVersion, other: SemVersion): Int {
// ignored metadata in comparing
// If $this equals $other (without metadata),
// return same.
if (other.mainVersion.contentEquals(mainVersion) && identifier == other.identifier) {
if (other.mainVersion.contentEquals(source.mainVersion) && source.identifier == other.identifier) {
return 0
}
fun IntArray.getSafe(index: Int) = getOrElse(index) { 0 }
// Compare main-version
for (index in 0 until (max(mainVersion.size, other.mainVersion.size))) {
val result = mainVersion.getSafe(index).compareTo(other.mainVersion.getSafe(index))
for (index in 0 until (max(source.mainVersion.size, other.mainVersion.size))) {
val result = source.mainVersion.getSafe(index).compareTo(other.mainVersion.getSafe(index))
if (result != 0) return result
}
// If main-versions are same.
var identifier0 = identifier
var identifier0 = source.identifier
var identifier1 = other.identifier
// If anyone doesn't have the identifier...
if (identifier0 == null || identifier1 == null) {

View File

@ -233,6 +233,6 @@ public data class SemVersion internal constructor(
* if it's greater than [other].
*/
public override operator fun compareTo(other: SemVersion): Int {
return SemVersionInternal.run { compareInternal(other) }
return SemVersionInternal.run { compareInternal(this@SemVersion, other) }
}
}