Created
May 4, 2016 08:35
-
-
Save Jire/a2dda12329654c650132acf23f37dbac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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