Last active
February 16, 2016 21:50
-
-
Save Jire/3f55c99d6f56ba0d4bce 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
| @file:JvmName("Stringa") | |
| package org.jire.stringa | |
| import java.util.* | |
| private val intToString = HashMap<Int, String>(8192) | |
| private val arrayToString = HashMap<Int, Int>(8192) | |
| fun String.stringa() { | |
| val hash = hashCode() | |
| if (!intToString.containsKey(hash)) { | |
| val array = toByteArray() | |
| intToString.put(hash, this) | |
| arrayToString.put(array.hashCode(), hash) | |
| } | |
| } | |
| fun Array<Byte>.stringa(): String { | |
| val hash = arrayToString[this.hashCode()] | |
| if (hash != null) return intToString[hash]!! | |
| var string = "" | |
| for (b in this) string += b.toChar() | |
| string.stringa() | |
| return string | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment