Skip to content

Instantly share code, notes, and snippets.

@Jire
Created May 4, 2016 08:35
Show Gist options
  • Save Jire/a2dda12329654c650132acf23f37dbac to your computer and use it in GitHub Desktop.
Save Jire/a2dda12329654c650132acf23f37dbac to your computer and use it in GitHub Desktop.
object StringCache {
private val map = HashMap<Int, String>(1024)
operator fun get(bytes: ByteArray, hash: Int = bytes.hashCode()): String {
if (map.containsKey(hash)) return map[hash]!!
val string = String(bytes).intern()
map[hash] = string
return string
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment