<commit_before>package io.jadon.sbhs

import java.awt.Color

object GBAColor {

    val fromCache = mutableMapOf<String, Color>()
    val toCache = mutableMapOf<Color, String>()

    fun fromGBA(hex: String): Color {
        assert(hex.length == 4) { "Woah! This string isn't 4 characters wide!" }

        if (fromCache.containsKey(hex)) {
            return fromCache[hex]!!
        }

        val n = Integer.parseInt(hex, 16)
        val r = (n and ((1 shl 5) - 1)) * 8 * (24 / 15)
        val g = ((n and (((1 shl 5) - 1) shl 5)) shr 5) * 8 * (24 / 15)
        val b = ((n and (((1 shl 5) - 1) shl 10)) shr 10) * 8 * (24 / 15)

        val c = Color(r, g, b)
        fromCache[hex] = c
        return c
    }

    fun toGBA(color: Color): String {
        if (toCache.containsKey(color)) {
            return toCache[color]!!
        }

        val dr = Math.min(31, Math.ceil(color.red / 8.0).toInt())
        val dg = Math.min(31, Math.ceil(color.green / 8.0).toInt())
        val db = Math.min(31, Math.ceil(color.blue / 8.0).toInt())
        val i = Math.min(0x7FFF, (db * 4 * 256) + (dg * 2 * 16) + dr)

        val hex = (if (i < Math.pow(16.0, 3.0)) "0" else "") +
                (if (i < 256) "0" else "") +
                (if (i < 16) "0" else "") +
                Integer.toHexString(i)

        toCache[color] = hex
        return hex
    }

    fun toInts(s: String): IntArray {
        assert(s.length == 4) { "Woah! This string isn't 4 characters wide!" }
        val c = s.toCharArray()
        val i = IntArray(2)
        i[0] = Integer.parseInt(c[0] + "" + c[1], 16)
        i[1] = Integer.parseInt(c[2] + "" + c[3], 16)
        return i
    }
}<commit_msg>Simplify GBAColor.fromGBA()<commit_after>package io.jadon.sbhs

import java.awt.Color

object GBAColor {

    private val fromCache = mutableMapOf<String, Color>()
    private val toCache = mutableMapOf<Color, String>()

    fun fromGBA(hex: String): Color {
        assert(hex.length == 4) { "Woah! This string isn't 4 characters wide!" }

        if (fromCache.containsKey(hex)) {
            return fromCache[hex]!!
        }

        val n = Integer.parseInt(hex, 16)
        val r = (n and ((1 shl 5) - 1)) * 8 * (24 / 15)
        val g = ((n and (((1 shl 5) - 1) shl 5)) shr 5) * 8 * (24 / 15)
        val b = ((n and (((1 shl 5) - 1) shl 10)) shr 10) * 8 * (24 / 15)

        val c = Color(r, g, b)
        fromCache[hex] = c
        return c
    }

    fun toGBA(color: Color): String {
        if (toCache.containsKey(color)) {
            return toCache[color]!!
        }

        val dr = Math.min(31, Math.ceil(color.red / 8.0).toInt())
        val dg = Math.min(31, Math.ceil(color.green / 8.0).toInt())
        val db = Math.min(31, Math.ceil(color.blue / 8.0).toInt())
        val i = Math.min(0x7FFF, (db * 4 * 256) + (dg * 2 * 16) + dr)

        val hex = Integer.toHexString(i).padStart(4, '0')

        toCache[color] = hex
        return hex
    }

}
{'fraction_non_alphanumeric': 0.16322384016254657, 'fraction_numerical': 0.0467321368100237, 'mean_word_length': 1.8875855327468232, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '964775', 'n_tokens_mistral': 1188, 'n_tokens_neox': 1064, 'n_words': 299}