mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-16 05:24:06 +09:00
replacing min/max usage with kotlin's
This commit is contained in:
@@ -5,6 +5,8 @@ import java.io.*
|
||||
import java.nio.channels.ClosedChannelException
|
||||
import java.nio.charset.Charset
|
||||
import java.nio.charset.UnsupportedCharsetException
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
|
||||
|
||||
/**
|
||||
@@ -65,7 +67,7 @@ class ByteArray64(initialSize: Long = BANK_SIZE.toLong()) {
|
||||
|
||||
try {
|
||||
__data[index.toBankNumber()][index.toBankOffset()] = value
|
||||
size = maxOf(size, index + 1)
|
||||
size = max(size, index + 1)
|
||||
}
|
||||
catch (e: IndexOutOfBoundsException) {
|
||||
val msg = "index: $index -> bank ${index.toBankNumber()} offset ${index.toBankOffset()}\n" +
|
||||
@@ -115,7 +117,7 @@ class ByteArray64(initialSize: Long = BANK_SIZE.toLong()) {
|
||||
// 3. Copy over the remaining bytes
|
||||
|
||||
// 1.
|
||||
var actualBytesToCopy = minOf(remainingBytesToCopy, remainingInHeadBank) // it is possible that size of the bytes is smaller than the remainingInHeadBank
|
||||
var actualBytesToCopy = min(remainingBytesToCopy, remainingInHeadBank) // it is possible that size of the bytes is smaller than the remainingInHeadBank
|
||||
System.arraycopy(bytes, srcCursor, __data[currentBankNumber], bankOffset, actualBytesToCopy)
|
||||
remainingBytesToCopy -= actualBytesToCopy
|
||||
srcCursor += actualBytesToCopy
|
||||
@@ -124,7 +126,7 @@ class ByteArray64(initialSize: Long = BANK_SIZE.toLong()) {
|
||||
// 2. and 3.
|
||||
while (remainingBytesToCopy > 0) {
|
||||
currentBankNumber += 1
|
||||
actualBytesToCopy = minOf(remainingBytesToCopy, BANK_SIZE) // it is possible that size of the bytes is smaller than the remainingInHeadBank
|
||||
actualBytesToCopy = min(remainingBytesToCopy, BANK_SIZE) // it is possible that size of the bytes is smaller than the remainingInHeadBank
|
||||
System.arraycopy(bytes, srcCursor, __data[currentBankNumber], 0, actualBytesToCopy)
|
||||
remainingBytesToCopy -= actualBytesToCopy
|
||||
srcCursor += actualBytesToCopy
|
||||
@@ -535,7 +537,7 @@ open class ByteArray64Reader(val ba: ByteArray64, val charset: Charset) : Reader
|
||||
surrogateLeftover = ' '
|
||||
}
|
||||
else {
|
||||
val bbuf = (0 until minOf(4L, remaining)).map { ba[readCursor + it] }
|
||||
val bbuf = (0 until min(4L, remaining)).map { ba[readCursor + it] }
|
||||
val charLen = utf8GetCharLen(bbuf[0])
|
||||
val codePoint = utf8decode(bbuf.subList(0, charLen))
|
||||
|
||||
@@ -573,7 +575,7 @@ open class ByteArray64Reader(val ba: ByteArray64, val charset: Charset) : Reader
|
||||
}
|
||||
}
|
||||
Charset.forName("CP437") -> {
|
||||
for (i in 0 until minOf(len.toLong(), remaining)) {
|
||||
for (i in 0 until min(len.toLong(), remaining)) {
|
||||
cbuf[(off + i).toInt()] = ba[readCursor].toChar()
|
||||
readCursor += 1
|
||||
readCount += 1
|
||||
|
||||
@@ -10,6 +10,7 @@ import java.util.zip.GZIPInputStream
|
||||
import java.util.zip.GZIPOutputStream
|
||||
import kotlin.collections.HashMap
|
||||
import kotlin.experimental.and
|
||||
import kotlin.math.min
|
||||
|
||||
/**
|
||||
* Temporarily disabling on-disk compression; it somehow does not work, compress the files by yourself!
|
||||
@@ -667,7 +668,7 @@ fun magicMismatch(magic: ByteArray, array: ByteArray): Boolean {
|
||||
fun String.toEntryName(length: Int, charset: Charset): ByteArray {
|
||||
val buf = ByteArray(length)
|
||||
val stringByteArray = this.toByteArray(charset)
|
||||
System.arraycopy(stringByteArray, 0, buf, 0, minOf(length, stringByteArray.size))
|
||||
System.arraycopy(stringByteArray, 0, buf, 0, min(length, stringByteArray.size))
|
||||
return buf
|
||||
}
|
||||
fun ByteArray.toCanonicalString(charset: Charset): String {
|
||||
|
||||
@@ -15,6 +15,7 @@ import java.util.logging.Level
|
||||
import javax.swing.*
|
||||
import javax.swing.table.AbstractTableModel
|
||||
import javax.swing.text.DefaultCaret
|
||||
import kotlin.math.min
|
||||
|
||||
|
||||
/**
|
||||
@@ -619,7 +620,7 @@ EntryID: ${file.entryID}
|
||||
ParentID: ${file.parentEntryID}""" + if (file.contents is EntryFile) """
|
||||
|
||||
Contents:
|
||||
${String(file.contents.bytes.sliceArray64(0L..minOf(PREVIEW_MAX_BYTES, file.contents.bytes.size) - 1).toByteArray(), sysCharset)}""" else ""
|
||||
${String(file.contents.bytes.sliceArray64(0L..min(PREVIEW_MAX_BYTES, file.contents.bytes.size) - 1).toByteArray(), sysCharset)}""" else ""
|
||||
}
|
||||
private fun setWindowTitleWithName(name: String) {
|
||||
this.title = "$appName - $name"
|
||||
|
||||
Reference in New Issue
Block a user