From 80393fc0e408e721d587a1839a36b7ff03676814 Mon Sep 17 00:00:00 2001 From: Gioyous The II <244157479+gioyous-it@users.noreply.github.com> Date: Fri, 28 Aug 2026 22:17:24 +0200 Subject: [PATCH 1/6] Fixes the excessive memory usage described in [GH-47](https://github.com/Bixilon/Minosoft/issues/47) Fixes the excessive memory usage described in [GH-47](https://github.com/Bixilon/Minosoft/issues/47). --- .../types/unicode/unihex/UnihexFontType.kt | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/font/types/unicode/unihex/UnihexFontType.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/font/types/unicode/unihex/UnihexFontType.kt index ec3b9916c..16e13d952 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/font/types/unicode/unihex/UnihexFontType.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/font/types/unicode/unihex/UnihexFontType.kt @@ -120,18 +120,17 @@ class UnihexFontType( return array } - private fun InputStream.readUnihex(chars: Int2ObjectOpenHashMap): Int { - val buffer = ByteArray(64) - var totalWidth = 0 - while (this.available() > 0) { - val codePoint = readHexInt() - if (codePoint == -1) continue - val data = this.readUnihexData(buffer) - chars[codePoint] = data - totalWidth += data.size / (UnifontRasterizer.HEIGHT / Byte.SIZE_BITS) - } - - return totalWidth - } - } -} + private fun InputStream.readUnihex(chars: Int2ObjectOpenHashMap): Int { + val buffer = ByteArray(64) + var totalWidth = 0 + while (this.available() > 0) { + val codePoint = readHexInt() + if (codePoint == -1) continue + val data = this.readUnihexData(buffer) + if (chars.putIfAbsent(codePoint, data) == null) { + totalWidth += data.size / (UnifontRasterizer.HEIGHT / Byte.SIZE_BITS) + } + } + + return totalWidth + } \ No newline at end of file From f507584e33aef5e63eac46a604f8f032662b8e50 Mon Sep 17 00:00:00 2001 From: Gioyous The II <244157479+gioyous-it@users.noreply.github.com> Date: Fri, 28 Aug 2026 22:37:24 +0200 Subject: [PATCH 2/6] Update copyright year and format license comment Updated copyright year from 2025 to 2026 and improved formatting in the license comment. --- .../types/unicode/unihex/UnihexFontType.kt | 47 +++++++++++-------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/font/types/unicode/unihex/UnihexFontType.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/font/types/unicode/unihex/UnihexFontType.kt index 16e13d952..52c863d14 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/font/types/unicode/unihex/UnihexFontType.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/font/types/unicode/unihex/UnihexFontType.kt @@ -1,14 +1,22 @@ /* * Minosoft - * Copyright (C) 2020-2025 Moritz Zwerger + * Copyright (C) 2020-2026 Moritz Zwerger * - * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . * - * This software is not affiliated with Mojang AB, the original developer of Minecraft. + * This software is not affiliated with Mojang AB, the original developer + * of Minecraft. */ package de.bixilon.minosoft.gui.rendering.font.types.unicode.unihex @@ -120,17 +128,18 @@ class UnihexFontType( return array } - private fun InputStream.readUnihex(chars: Int2ObjectOpenHashMap): Int { - val buffer = ByteArray(64) - var totalWidth = 0 - while (this.available() > 0) { - val codePoint = readHexInt() - if (codePoint == -1) continue - val data = this.readUnihexData(buffer) - if (chars.putIfAbsent(codePoint, data) == null) { - totalWidth += data.size / (UnifontRasterizer.HEIGHT / Byte.SIZE_BITS) - } - } - - return totalWidth - } \ No newline at end of file + private fun InputStream.readUnihex(chars: Int2ObjectOpenHashMap): Int { + val buffer = ByteArray(64) + var totalWidth = 0 + while (this.available() > 0) { + val codePoint = readHexInt() + if (codePoint == -1) continue + val data = readUnihexData(buffer) + if (chars.putIfAbsent(codePoint, data) == null) { + totalWidth += data.size / (UnifontRasterizer.HEIGHT / Byte.SIZE_BITS) + } + } + + return totalWidth + } + } From fa0e9430918927a4908b1b75aefe599437816ff8 Mon Sep 17 00:00:00 2001 From: Gioyous The II <244157479+gioyous-it@users.noreply.github.com> Date: Fri, 28 Aug 2026 22:39:22 +0200 Subject: [PATCH 3/6] Update UnihexFontType.kt --- .../font/types/unicode/unihex/UnihexFontType.kt | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/font/types/unicode/unihex/UnihexFontType.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/font/types/unicode/unihex/UnihexFontType.kt index 52c863d14..d1e99e660 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/font/types/unicode/unihex/UnihexFontType.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/font/types/unicode/unihex/UnihexFontType.kt @@ -2,21 +2,13 @@ * Minosoft * Copyright (C) 2020-2026 Moritz Zwerger * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License along with this program. If not, see . * - * This software is not affiliated with Mojang AB, the original developer - * of Minecraft. + * This software is not affiliated with Mojang AB, the original developer of Minecraft. */ package de.bixilon.minosoft.gui.rendering.font.types.unicode.unihex From 3fce6c9b630fb9eb2dedb5ad6b9d86d9202870f1 Mon Sep 17 00:00:00 2001 From: Gioyous The II <244157479+gioyous-it@users.noreply.github.com> Date: Fri, 28 Aug 2026 22:44:33 +0200 Subject: [PATCH 4/6] Fix formatting and improve comments in UnihexFontType.kt --- .../types/unicode/unihex/UnihexFontType.kt | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/font/types/unicode/unihex/UnihexFontType.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/font/types/unicode/unihex/UnihexFontType.kt index d1e99e660..9b9baf6e9 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/font/types/unicode/unihex/UnihexFontType.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/font/types/unicode/unihex/UnihexFontType.kt @@ -2,7 +2,7 @@ * Minosoft * Copyright (C) 2020-2026 Moritz Zwerger * - * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. * @@ -120,6 +120,40 @@ class UnihexFontType( return array } + private fun InputStream.readUnihex(chars: Int2ObjectOpenHashMap): Int { + val buffer = ByteArray(64) + var totalWidth = 0 + while (this.available() > 0) { + val codePoint = readHexInt() + if (codePoint == -1) continue + val data = readUnihexData(buffer) + if (chars.putIfAbsent(codePoint, data) == null) { + totalWidth += data.size / (UnifontRasterizer.HEIGHT / Byte.SIZE_BITS) + } + } + + return totalWidth + } + } +} if (byte == '\n'.code) break // separator + val hex = byte.fromHex() + if (hex < 0) throw IllegalArgumentException("Invalid hex char: ${byte.toChar()}!") + + + if (index % 2 == 0) { + // most significant bits + buffer[index / 2] = ((buffer[index / 2].toInt() and 0x0F) or (hex shl 4)).toByte() + } else { + buffer[index / 2] = ((buffer[index / 2].toInt() and 0xF0) or hex).toByte() + } + index++ + } + + val array = ByteArray(index / 2) + System.arraycopy(buffer, 0, array, 0, array.size) + return array + } + private fun InputStream.readUnihex(chars: Int2ObjectOpenHashMap): Int { val buffer = ByteArray(64) var totalWidth = 0 From de45d2908ba879f53dd014c8c279e8f2e2033162 Mon Sep 17 00:00:00 2001 From: Gioyous The II <244157479+gioyous-it@users.noreply.github.com> Date: Fri, 28 Aug 2026 22:50:08 +0200 Subject: [PATCH 5/6] Refactor UnihexFontType.kt for improved readability --- .../types/unicode/unihex/UnihexFontType.kt | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/font/types/unicode/unihex/UnihexFontType.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/font/types/unicode/unihex/UnihexFontType.kt index 9b9baf6e9..a04de2909 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/font/types/unicode/unihex/UnihexFontType.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/font/types/unicode/unihex/UnihexFontType.kt @@ -2,7 +2,7 @@ * Minosoft * Copyright (C) 2020-2026 Moritz Zwerger * - * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. * @@ -154,6 +154,40 @@ class UnihexFontType( return array } + private fun InputStream.readUnihex(chars: Int2ObjectOpenHashMap): Int { + val buffer = ByteArray(64) + var totalWidth = 0 + while (this.available() > 0) { + val codePoint = readHexInt() + if (codePoint == -1) continue + val data = readUnihexData(buffer) + if (chars.putIfAbsent(codePoint, data) == null) { + totalWidth += data.size / (UnifontRasterizer.HEIGHT / Byte.SIZE_BITS) + } + } + + return totalWidth + } + } +} if (byte == '\n'.code) break // separator + val hex = byte.fromHex() + if (hex < 0) throw IllegalArgumentException("Invalid hex char: ${byte.toChar()}!") + + + if (index % 2 == 0) { + // most significant bits + buffer[index / 2] = ((buffer[index / 2].toInt() and 0x0F) or (hex shl 4)).toByte() + } else { + buffer[index / 2] = ((buffer[index / 2].toInt() and 0xF0) or hex).toByte() + } + index++ + } + + val array = ByteArray(index / 2) + System.arraycopy(buffer, 0, array, 0, array.size) + return array + } + private fun InputStream.readUnihex(chars: Int2ObjectOpenHashMap): Int { val buffer = ByteArray(64) var totalWidth = 0 From fcb77a00e9ba8f188706baec06c3ac3ae602dfb0 Mon Sep 17 00:00:00 2001 From: Gioyous The II <244157479+gioyous-it@users.noreply.github.com> Date: Fri, 28 Aug 2026 22:58:50 +0200 Subject: [PATCH 6/6] Remove unused methods and clean up UnihexFontType --- .../types/unicode/unihex/UnihexFontType.kt | 69 +------------------ 1 file changed, 1 insertion(+), 68 deletions(-) diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/font/types/unicode/unihex/UnihexFontType.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/font/types/unicode/unihex/UnihexFontType.kt index a04de2909..e2b88a005 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/font/types/unicode/unihex/UnihexFontType.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/font/types/unicode/unihex/UnihexFontType.kt @@ -135,71 +135,4 @@ class UnihexFontType( return totalWidth } } -} if (byte == '\n'.code) break // separator - val hex = byte.fromHex() - if (hex < 0) throw IllegalArgumentException("Invalid hex char: ${byte.toChar()}!") - - - if (index % 2 == 0) { - // most significant bits - buffer[index / 2] = ((buffer[index / 2].toInt() and 0x0F) or (hex shl 4)).toByte() - } else { - buffer[index / 2] = ((buffer[index / 2].toInt() and 0xF0) or hex).toByte() - } - index++ - } - - val array = ByteArray(index / 2) - System.arraycopy(buffer, 0, array, 0, array.size) - return array - } - - private fun InputStream.readUnihex(chars: Int2ObjectOpenHashMap): Int { - val buffer = ByteArray(64) - var totalWidth = 0 - while (this.available() > 0) { - val codePoint = readHexInt() - if (codePoint == -1) continue - val data = readUnihexData(buffer) - if (chars.putIfAbsent(codePoint, data) == null) { - totalWidth += data.size / (UnifontRasterizer.HEIGHT / Byte.SIZE_BITS) - } - } - - return totalWidth - } - } -} if (byte == '\n'.code) break // separator - val hex = byte.fromHex() - if (hex < 0) throw IllegalArgumentException("Invalid hex char: ${byte.toChar()}!") - - - if (index % 2 == 0) { - // most significant bits - buffer[index / 2] = ((buffer[index / 2].toInt() and 0x0F) or (hex shl 4)).toByte() - } else { - buffer[index / 2] = ((buffer[index / 2].toInt() and 0xF0) or hex).toByte() - } - index++ - } - - val array = ByteArray(index / 2) - System.arraycopy(buffer, 0, array, 0, array.size) - return array - } - - private fun InputStream.readUnihex(chars: Int2ObjectOpenHashMap): Int { - val buffer = ByteArray(64) - var totalWidth = 0 - while (this.available() > 0) { - val codePoint = readHexInt() - if (codePoint == -1) continue - val data = readUnihexData(buffer) - if (chars.putIfAbsent(codePoint, data) == null) { - totalWidth += data.size / (UnifontRasterizer.HEIGHT / Byte.SIZE_BITS) - } - } - - return totalWidth - } - } +}